[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface loncommon.pm

raeburn raeburn at source.lon-capa.org
Sat Aug 3 18:32:01 EDT 2013


raeburn		Sat Aug  3 22:32:01 2013 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	loncommon.pm 
  Log:
  - For 2.11
    - Backport 1.1136, 1.1137, 1.1138, 1.1139, 1.1140, 1.1141, 1.1142 (part).
  
  
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1075.2.41 loncom/interface/loncommon.pm:1.1075.2.42
--- loncom/interface/loncommon.pm:1.1075.2.41	Fri Jul  5 19:53:11 2013
+++ loncom/interface/loncommon.pm	Sat Aug  3 22:32:01 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1075.2.41 2013/07/05 19:53:11 raeburn Exp $
+# $Id: loncommon.pm,v 1.1075.2.42 2013/08/03 22:32:01 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2161,7 +2161,7 @@
 
 =pod
 
-=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoma,$excdoms)
+=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
 
 Returns a string containing a <select name='$name' size='1'> form to 
 allow a user to select the domain to preform an operation in.  
@@ -2319,6 +2319,10 @@
 
 =item * $clientos
 
+=item * $clientmobile
+
+=item * $clientinfo
+
 =back
 
 =back 
@@ -2337,6 +2341,7 @@
     my $clientversion='0';
     my $clientmathml='';
     my $clientunicode='0';
+    my $clientmobile=0;
     for (my $i=0;$i<=$#browsertype;$i++) {
         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
@@ -2348,6 +2353,7 @@
 	}
     }
     my $clientos='unknown';
+    my $clientinfo;
     if (($httpbrowser=~/linux/i) ||
         ($httpbrowser=~/unix/i) ||
         ($httpbrowser=~/ux/i) ||
@@ -2359,8 +2365,16 @@
         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
     if ($httpbrowser=~/win/i) { $clientos='win'; }
     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
+    if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
+        $clientmobile=lc($1);
+    }
+    if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
+        $clientinfo = 'firefox-'.$1;
+    } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
+        $clientinfo = 'chromeframe-'.$1;
+    }
     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
-            $clientunicode,$clientos,);
+            $clientunicode,$clientos,$clientmobile,$clientinfo);
 }
 
 ###############################################################
@@ -3220,7 +3234,7 @@
 # ------------------------------------------------------------- Confirm Wrapper
 =pod
 
-=item confirmwrapper
+=item * &confirmwrapper($message)
 
 Wrap messages about completion of operation in box
 
@@ -7292,6 +7306,11 @@
 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
         .$inhibitprint
 	.$head_extra;
+    if ($env{'browser.mobile'}) {
+        $result .= '
+<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
+<meta name="apple-mobile-web-app-capable" content="yes" />';
+    }
     return $result.'</head>';
 }
 
@@ -7632,12 +7651,12 @@
 		$(".LCmodal-overlay").click(function(){modalWindow.close();});
 	}
 };
-	var openMyModal = function(source,width,height,scrolling)
+	var openMyModal = function(source,width,height,scrolling,transparency,style)
 	{
 		modalWindow.windowId = "myModal";
 		modalWindow.width = width;
 		modalWindow.height = height;
-		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'>&lt/iframe>";
+		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'>&lt/iframe>";
 		modalWindow.open();
 	};	
 // END LON-CAPA Internal -->
@@ -7647,16 +7666,18 @@
 }
 
 sub modal_link {
-    my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
+    my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
     unless ($width) { $width=480; }
     unless ($height) { $height=400; }
     unless ($scrolling) { $scrolling='yes'; }
+    unless ($transparency) { $transparency='true'; }
+
     my $target_attr;
     if (defined($target)) {
         $target_attr = 'target="'.$target.'"';
     }
     return <<"ENDLINK";
-<a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
+<a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
            $linktext</a>
 ENDLINK
 }
@@ -7684,10 +7705,10 @@
     my $innerwidth=$width-20;
     $content=&js_ready(
                &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
-                 &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
-                    $content.
+                 &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
+                 $content.
                  &end_scrollbox().
-               &end_page()
+                 &end_page()
              );
     return &modal_adhoc_script($funcname,$width,$height,$content);
 }
@@ -7904,20 +7925,27 @@
 
 
 sub start_scrollbox {
-    my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
+    my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready)=@_;
     unless ($outerwidth) { $outerwidth='520px'; }
     unless ($width) { $width='500px'; }
     unless ($height) { $height='200px'; }
     my ($table_id,$div_id,$tdcol);
     if ($id ne '') {
-        $table_id = " id='table_$id'";
-        $div_id = " id='div_$id'";
+        $table_id = ' id="table_'.$id.'"';
+        $div_id = ' id="div_'.$id.'"';
     }
     if ($bgcolor ne '') {
         $tdcol = "background-color: $bgcolor;";
     }
+    my $nicescroll_js;
+    if ($env{'browser.mobile'}) {
+        $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
+    }
     return <<"END";
-<table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol"><div style="overflow:auto; width:$width; height: $height;"$div_id>
+$nicescroll_js
+
+<table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
+<div style="overflow:auto; width:$width; height: $height;"$div_id>
 END
 }
 
@@ -7925,6 +7953,87 @@
     return '</div></td></tr></table>';
 }
 
+sub nicescroll_javascript {
+    my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
+    my %options;
+    if (ref($cursor) eq 'HASH') {
+        %options = %{$cursor};
+    }
+    unless ($options{'railalign'} =~ /^left|right$/) {
+        $options{'railalign'} = 'left';
+    }
+    unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
+        my $function  = &get_users_function();
+        $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
+        unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
+            $options{'cursorcolor'} = '#00F';
+        }
+    }
+    if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
+        unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
+            $options{'cursoropacity'}='1.0';
+        }
+    } else {
+        $options{'cursoropacity'}='1.0';
+    }
+    if ($options{'cursorfixedheight'} eq 'none') {
+        delete($options{'cursorfixedheight'});
+    } else {
+        unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
+    }
+    unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
+        delete($options{'railoffset'});
+    }
+    my @niceoptions;
+    while (my($key,$value) = each(%options)) {
+        if ($value =~ /^\{.+\}$/) {
+            push(@niceoptions,$key.':'.$value);
+        } else {
+            push(@niceoptions,$key.':"'.$value.'"');
+        }
+    }
+    my $nicescroll_js = '
+$(document).ready(
+      function() {
+          $("#'.$id.'").niceScroll({'.join(',', at niceoptions).'});
+      }
+);
+';
+    if ($framecheck) {
+        $nicescroll_js .= '
+function expand_div(caller) {
+    if (top === self) {
+        document.getElementById("'.$id.'").style.width = "auto";
+        document.getElementById("'.$id.'").style.height = "auto";
+    } else {
+        try {
+            if (parent.frames) {
+                if (parent.frames.length > 1) {
+                    var framesrc = parent.frames[1].location.href;
+                    var currsrc = framesrc.replace(/\#.*$/,"");
+                    if ((caller == "search") || (currsrc == "'.$location.'")) {
+                        document.getElementById("'.$id.'").style.width = "auto";
+                        document.getElementById("'.$id.'").style.height = "auto";
+                    }
+                }
+            }
+        } catch (e) {
+            return;
+        }
+    }
+    return;
+}
+';
+    }
+    if ($needjsready) {
+        $nicescroll_js = '
+<script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
+    } else {
+        $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
+    }
+    return $nicescroll_js;
+}
+
 sub simple_error_page {
     my ($r,$title,$msg) = @_;
     my $page =
@@ -8556,6 +8665,8 @@
 2. user's domain
 3. quota name - portfolio, author, or course
    (if no quota name provided, defaults to portfolio).
+4. crstype - official, unofficial or community, if quota name is
+   course
 
 Returns:
 1. Disk quota (in Mb) assigned to student.
@@ -8577,7 +8688,7 @@
 
 
 sub get_user_quota {
-    my ($uname,$udom,$quotaname) = @_;
+    my ($uname,$udom,$quotaname,$crstype) = @_;
     my ($quota,$quotatype,$settingstatus,$defquota);
     if (!defined($udom)) {
         $udom = $env{'user.domain'};
@@ -8628,7 +8739,12 @@
         if ($quota eq '' || wantarray) {
             if ($quotaname eq 'course') {
                 my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
-                $defquota = $domdefs{'uploadquota'};
+                if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
+                    $defquota = $domdefs{$crstype.'quota'};
+                }
+                if ($defquota eq '') {
+                    $defquota = 500;
+                }
             } else {
                 ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
             }
@@ -8657,6 +8773,7 @@
 given an (optional) user's institutional status.
 
 Incoming parameters:
+
 1. domain
 2. (Optional) institutional status(es).  This is a : separated list of 
    status types (e.g., faculty, staff, student etc.)
@@ -8667,6 +8784,7 @@
    (if no quota name provided, defaults to portfolio).
 
 Returns:
+
 1. Default disk quota (in Mb) for user portfolios in the domain.
 2. (Optional) institutional type which determined the value of the
    default quota.
@@ -8680,8 +8798,6 @@
 the largest default quota which applies to the user determines the
 default quota returned.
 
-=back
-
 =cut
 
 ###############################################
@@ -8730,6 +8846,11 @@
                 $defquota = $quotahash{'quotas'}{'default'};
             }
             $settingstatus = 'default';
+            if ($defquota eq '') {
+                if ($quotaname eq 'author') {
+                    $defquota = 500;
+                }
+            }
         }
     } else {
         $settingstatus = 'default';
@@ -8750,15 +8871,19 @@
 
 =pod
 
-=item * &excess_filesize_authorspace()
+=item * &excess_filesize_warning()
 
 Returns warning message if upload of file to authoring space, or copying
-of existing file within authoring space will cause quota to be exceeded.
+of existing file within authoring space will cause quota for the authoring
+space to be exceeded.
+
+Same, if upload of a file directly to a course/community via Course Editor
+will cause quota for uploaded content for the course to be exceeded.
 
 Inputs: 6
-1. username
+1. username or coursenum
 2. domain
-3. directory path for top level of current authoring space
+3. context ('author' or 'course')
 4. filename of file for which action is being requested
 5. filesize (kB) of file
 6. action being taken: copy or upload.
@@ -8766,13 +8891,23 @@
 Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
          otherwise return null.
 
+=back
+
 =cut
 
-sub excess_filesize_authorspace {
-    my ($uname,$udom,$authorspace,$filename,$filesize,$action) = @_;
-    my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in MB
+sub excess_filesize_warning {
+    my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
+    my $current_disk_usage = 0;
+    my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
+    if ($context eq 'author') {
+        my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
+        $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
+    } else {
+        foreach my $subdir ('docs','supplemental') {
+            $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
+        }
+    }
     $disk_quota = int($disk_quota * 1000);
-    my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
     if (($current_disk_usage + $filesize) > $disk_quota) {
         return '<p><span class="LC_warning">'.
                 &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
@@ -14145,7 +14280,7 @@
 # ------------------------------------ Check browser type and MathML capability
 
     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
-        $clientunicode,$clientos) = &decode_user_agent($r);
+        $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
 
 # ------------------------------------------------------------- Get environment
 
@@ -14176,6 +14311,8 @@
 	     "browser.mathml"     => $clientmathml,
 	     "browser.unicode"    => $clientunicode,
 	     "browser.os"         => $clientos,
+             "browser.mobile"     => $clientmobile,
+             "browser.info"       => $clientinfo,
 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
 	     "request.course.fn"  => '',
 	     "request.course.uri" => '',


More information about the LON-CAPA-cvs mailing list