[LON-CAPA-cvs] cvs: modules /msu localenroll.pm localstudentphoto.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 07 Feb 2006 05:14:07 -0000


This is a MIME encoded message

--raeburn1139289247
Content-Type: text/plain

raeburn		Tue Feb  7 00:14:07 2006 EDT

  Modified files:              
    /modules/msu	localenroll.pm localstudentphoto.pm 
  Log:
  MSU-specific routines for import of student photos from AIS repository (only works on s10), and conditions of use of digital student photos; acceptance by course owner is required for photos to be usable in a course.
  
  
--raeburn1139289247
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060207001407.txt"

Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.15 modules/msu/localenroll.pm:1.16
--- modules/msu/localenroll.pm:1.15	Thu Jan 20 14:34:29 2005
+++ modules/msu/localenroll.pm	Tue Feb  7 00:14:03 2006
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for
 # automated enrollment
-# $Id: localenroll.pm,v 1.15 2005/01/20 19:34:29 raeburn Exp $
+# $Id: localenroll.pm,v 1.16 2006/02/07 05:14:03 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,6 +30,7 @@
 use DBI;
 use LONCAPA::Configuration;
 use Apache::lonnet;
+use localstudentphoto;
 
 sub run () {
     my $dom = shift;
@@ -334,4 +335,113 @@
     return $owner;
 }
 
+sub institutional_photos {
+    my ($dom,$crs,$affiliates,$result,$action,$students) = @_;
+    my $outcome;
+    if ($action eq 'update') {
+        my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
+        my ($dbh,$dbflag) = &connect_DB($$configvars{'lonDaemons'},'RO');
+        my $owner;
+        if ($dbflag) {
+            my %stuinfo;
+            foreach my $class (@{$$affiliates{$crs}}) {
+                if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
+# Check if section exists in LONCAPA table.
+                    my $sectioncheck = $dbh->selectrow_array(
+                         "SELECT count(*) FROM LONCAPA ". 
+                         "WHERE Term_Code = '$1' AND Subj_Code = '$2' ". 
+                         "AND Crse_Code = '$3' AND Sctn_Code = '$4'");
+                    if ($sectioncheck == 0) {
+                        unless ($owner eq '') {
+                            $owner = &get_owner($dom,$crs);
+                        }
+                        unless ($owner eq '' || !defined($owner)) {
+                            my $outcome = &new_course($class,$owner,$dom);
+                            if ($outcome eq 'ok') {
+                                $sectioncheck = 1;
+                            }
+                        }
+                    }
+                    if ($sectioncheck > 0) {
+                        my $pidcount = 0;
+                        my $blankcount = 1;
+                        my $maxtries = 5;
+                        my $numtries = 0;
+                        while (($numtries < $maxtries) && ($blankcount > 0)) {
+                            ($pidcount,$blankcount) = &get_pids_usernames($dbh,
+                                                             $class,\%stuinfo);
+                            $numtries ++;
+                        }
+                    }
+                }
+            }
+            &disconnect_DB($dbh);
+            foreach my $pid (sort(keys(%stuinfo))) {
+                if ($stuinfo{$pid}) {
+                    my $response = '';
+                    my $dest = &localstudentphoto::fetch($dom,$stuinfo{$pid},
+                                                              $pid,\$response);
+                    if ($response) {
+                        $$result{$response}.=$stuinfo{$pid}.'&';
+                }
+            }
+            $outcome = 'ok';
+        }
+    }
+    foreach my $type (keys(%{$result})) {
+        $$result{$type} =~ s/\&$//;
+    }
+    return $outcome;
+}
+
+sub get_pids_usernames {
+    my ($dbh,$class,$stuinfo) = @_;
+    my $pidcount = 0;
+    my $blankcount = 0;
+    if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
+        eval {
+            my $sth = $dbh->prepare("SELECT Pid,Pilot_Id FROM LONCAPA_ClassList WHERE Term_Code = '$1' AND Subj_Code = '$2' AND Crse_Code = '$3' AND Sctn_Code = '$4'  ORDER BY Pid");
+            $sth->execute();
+            while ( my($pid,$pilot,$name)  = $sth->fetchrow_array ) {
+                if ($pid =~ m/^A\d{8}$/i) {
+                    $$stuinfo{$pid} = $pilot;
+                    $pidcount ++;
+                } elsif ($pilot eq '') {
+                    $blankcount ++;
+                }
+            }
+            $sth->finish;
+        };
+    }
+    return ($pidcount,$blankcount);
+}
+
+sub photo_permission {
+    my ($dom,$perm_reqd,$conditions) = @_;
+    $$perm_reqd = 'yes';
+    $$conditions = "Student ID Image Policy\n
+In accordance with the guidelines put forth under the University's administrative ruling governing the release of student data, and the University Committee on Security and Confidentiality, student digitized images are to be considered confidential data.\n
+As such, student digitized images are provided to appropriate University personnel for these specific purposes: inclusion in various academic processes (e.g. personalized homework assignments, personalized examinations, etc.), for student face/name recognition (e.g., a seating chart), or, for inclusion in an adviser file.\n
+The following requirements must be understood and adhered to:\n
+# Images will only be used for one of the above purposes.
+# Images will not be re-transmitted, shared or otherwise reproduced.
+# Images will be purged at the end of the term, or other shorter time period.
+# If individual students request their images not be used, such requests will be honored.
+# If images are used for identification purposes during exams, provisions will be made such that the photo is always separated or detached from the exam itself before grading (preferably by the student or in the student's presence).\n
+By using this system to access Student Images, you are held responsible for adhering to the above policy.";
+    my $outcome = 'ok';
+    return $outcome;
+}
+
+sub manager_photo_update {
+    my ($dom) = @_;
+    my $update = 1;
+    my $comment = 
+"You can now choose to update the photo repository. As this may require \n".
+"copying student photo files from your institution's central data store, \n".
+"this may take several seconds to complete, especially for classes with \n".
+"large enrollments.";
+    return ($update,$comment);
+}
+
 1;
Index: modules/msu/localstudentphoto.pm
diff -u modules/msu/localstudentphoto.pm:1.1 modules/msu/localstudentphoto.pm:1.2
--- modules/msu/localstudentphoto.pm:1.1	Fri Nov 12 16:16:42 2004
+++ modules/msu/localstudentphoto.pm	Tue Feb  7 00:14:03 2006
@@ -1,6 +1,6 @@
 # The LON-CAPA dummy student photo fetch mechnism
 #
-# $Id: localstudentphoto.pm,v 1.1 2004/11/12 21:16:42 albertel Exp $
+# $Id: localstudentphoto.pm,v 1.2 2006/02/07 05:14:03 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,22 +33,130 @@
 use GDBM_File;
 
 sub fetch {
-    my ($domain,$user)=@_;
-    my $userdir=&main::propath($domain,$user);
-    my $dest=$userdir.'/userfiles/internal/studentphoto.jpg';
-    if (-e $dest) { return $dest; }
-    my %hash;
-    if (!tie(%hash,'GDBM_File',$userdir.'/environment.db',&GDBM_READER(),0640)) {
-	&main::logthis("Failed to tie $@ $!");
-	return '';
-    }
-    my $id=uc($hash{'id'});
-    untie(%hash);
-    if (!$id) { return ''; }
-    system("/bin/cp /home/albertel/estemp/$id.jpg $dest"); 
+    my ($udom,$uname,$pid,$response) = @_;
+    my $temptxt = '';
+    unless (ref($response)) {
+        $response = \$temptxt;
+    }
+    if ($udom eq '' || $uname eq '') {
+        $$response = 'nouser';
+        return '';
+    }
+    my $userdir=&main::propath($udom,$uname);
+    my $filepath = '/userfiles/internal/studentphoto.jpg';
+    my $thumbnail = '/userfiles/internal/studentphoto_tn.gif';
+    my $dest=$userdir.$filepath;
+    my $source;
+    my $destlastmod = 0;
+    my $sourcelastmod = 0;
+    if (!defined($pid)) {
+        my %hash;
+        if (!tie(%hash,'GDBM_File',$userdir.'/environment.db',&GDBM_READER(),                                                                        0640)) {
+            &main::logthis("Failed to tie $@ $!");
+            $$response = 'noid';
+            return '';
+        }
+        my $id=uc($hash{'id'});
+        untie(%hash);
+        if (!$id) {
+            $$response = 'noid';
+            return '';
+        }
+        $pid = $id;
+    }
+    if ($pid =~ /^(A\d{7})(\d)/i) {
+        $source = '/mnt/photos/'.lc($1).'.'.$2.'jp';
+        if (-e "$source") {
+            my @fileinfo = stat("$source");
+            $sourcelastmod = $fileinfo[9];
+        }
+    }
+    if (-e "$dest") {
+        my @currinfo = stat("$dest");
+        $destlastmod = $currinfo[9];
+        if ($sourcelastmod > 0) {
+            if ($sourcelastmod > $destlastmod) {
+                my $result = &copy_photo($udom,$source,$userdir,$filepath,
+                                                                   $thumbnail);
+                if ($result == 0) {
+                    $$response = 'update';
+                } else {
+                    $$response = 'error';
+                }
+            }
+        }
+    } elsif ($sourcelastmod > 0) {
+        my $result = &copy_photo($udom,$source,$userdir,$filepath,$thumbnail);
+        if ($result == 0) {
+            $$response = 'new';
+        } else {
+            $$response = 'error';
+        }
+    } else {
+        $$response = 'missing';
+    }
+    if (!$$response) { $$response = 'same'; } 
     if (-e $dest) { return $dest; }
     return '';
 }
 
+sub fetch_thumbnail {
+    my ($udom,$uname) = @_;
+    my $userdir=&main::propath($udom,$uname);
+    my $filepath = '/userfiles/internal/studentphoto.jpg';
+    my $thumbnail = '/userfiles/internal/studentphoto_tn.gif';
+    my $source =  $userdir.$filepath;
+    my $dest = $userdir.$thumbnail;
+    if (-e $dest) {
+        return $dest;
+    } else {
+        if (!-e $source) {
+            my $file = &fetch($udom,$uname);
+        }
+        if (-e $source) {
+            my ($fullsize,$thumbsize) = &localstudentphoto::thumbsettings($udom);
+            if ($fullsize && $thumbsize) {
+                system("convert -size $fullsize $source -thumbnail $thumbsize $dest");
+            }
+            if (-e $dest) {
+                return $dest;
+            }
+        }
+    }
+    return '';
+}
+
+sub copy_photo {
+    my ($udom,$source,$userdir,$filepath,$thumbnail) = @_;
+    my $errorcode = 1;
+    if (-e "$userdir") {
+        my @parts=split(/\//,$filepath);
+        my $fullpath=$userdir;
+        for (my $i=1;$i<@parts-1;$i++) {
+            $fullpath .= '/'.$parts[$i];
+            if ((-e $fullpath)!=1) {
+                mkdir($fullpath,0750);
+            }
+        }
+        my $dest=$userdir.$filepath;
+        my $dest_tn=$userdir.$thumbnail;
+        $errorcode=system("/bin/cp $source $dest");
+        unless ($errorcode) {
+            my ($fullsize,$thumbsize)=&localstudentphoto::thumbsettings($udom);
+            if ($fullsize && $thumbsize) {
+                system("convert -size $fullsize $dest -thumbnail $thumbsize $dest_tn");
+            }
+        }
+    }
+    return $errorcode;
+}
+
+sub thumbsettings {
+    my ($dom)=@_;
+    my $fullsize='240x240';
+    my $thumbsize='40x40';
+    return ($fullsize,$thumbsize); 
+}
+
 1;
 __END__

--raeburn1139289247--