--- loncom/interface/printout.pl 2004/09/09 15:30:49 1.69
+++ loncom/interface/printout.pl 2015/03/09 19:07:09 1.160
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
#
-# $Id: printout.pl,v 1.69 2004/09/09 15:30:49 matthew Exp $
+# $Id: printout.pl,v 1.160 2015/03/09 19:07:09 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,17 +27,139 @@
#
use lib '/home/httpd/lib/perl';
-use LONCAPA::loncgi();
+use LONCAPA::loncgi;
use File::Path;
+use File::Basename;
+use File::Copy;
use IO::File;
use Image::Magick;
-use Apache::lonhtmlcommon;
-use Apache::loncommon;
+use Apache::lonhtmlcommon();
+use Apache::lonnet;
+use Apache::loncommon();
use Apache::lonlocal;
+use Apache::lonmsg();
+use LONCAPA::Enrollment;
+use LONCAPA::Configuration;
use strict;
+
+my $busy_wait_timeout = 30;
+my $pdfs_converted = 0; # non zero if PDF includes (need to fixps).
+
+my $debugging = 0;
+
+sub debug {
+ if ($debugging) {
+ my ($text) = @_;
+ print "$text
\n";
+ }
+}
+
+# Determine if a user is operating as a student for this course/domain.
+#Parameters:
+# none
+#Implicit:
+# $env{request.role} contains the role under which this user operated this
+# this request.
+sub is_student {
+ return ($env{'request.role'}=~/^st\./);
+}
+
+#
+# Debugging: Dump the environment for debugging.
+#
+sub dumpenv {
+ print "
-------------------
";
+ foreach my $key (sort (keys %env)) {
+ print "
$key -> $env{$key}";
+ }
+ print "
-------------------
";
+}
+
+#
+# This sub sends a message to the appropriate person if there was an error
+# rendering the latex At present, there's only one case to consider:
+# a student printing inside a course results in messages to the course coordinator.
+#Parmaeters:
+# identifier - The unique identifier of this cgi request.
+# badresource- Filepath to most likely failing
+# logfile - The contents of the log file (included in the message).
+# texfile - reference to an array containing the LaTeX input file
+# (included in the message).
+#Implicit inputs:
+# From the environment:
+# cgi.$identifier.user - User doing the printing.
+# cgi.$identifier.domain - Domain the user is logged in on with printing.
+# cgi.$identifier.courseid - Id of the course (if this is a course).
+# cgi.$identifier.coursedom- Domain in which course was constituted.
+# cgi.$identifier.resources - List of resource URL's for which the print
+# was attempted.
+#
+sub send_error_mail {
+ my ($identifier, $badresource, $logfile, $texfile) = @_;
+ my $user = $env{"cgi.$identifier.user"};
+ my $domain = $env{"cgi.$identifier.domain"};
+ my $courseid = $env{"cgi.$identifier.courseid"};
+ my $coursedom= $env{"cgi.$identifier.coursedom"};
+ my $resources= $env{"cgi.$identifier.resources"};
+
+ # resource file->URL
+ #
+ my $badurl = &Apache::lonnet::declutter($badresource);
+
+ # &dumpenv();
+
+
+
+ # Only continue if there is a user, domain, courseid, course domain
+ # and resources:
+
+ if(defined($user) && defined($domain) && defined($courseid) &&
+ defined($coursedom) && defined($resources) ){
+
+ # Only mail if the conditions are ripe for it:
+ # The user is a student in the course:
+ #
+
+ if (&is_student()) {
+ # build the subject and message body:
+ &debug("sending message to course coordinators.");
+
+ # Todo: Convert badurl into a url from file path:
+
+ my $subject = "Error [$badurl] Print failed for $user".':'.$domain;
+ my $message .= "Print failed to render LaTeX for $user".':'."$domain\n";
+ $message .= " User was attempting to print: \n";
+ foreach my $resource (split(/:/,$resources)) {
+ $message .= " $resource\n";
+ }
+ $message .= "--------------------LaTeX logfile:------------ \n";
+ $message .= $logfile;
+ $message .= "-----------------LaTeX source file: ------------\n";
+
+ foreach my $line (@$texfile) {
+ $message .= "$line\n";
+ }
+ my (undef, %receivers) = &Apache::lonmsg::decide_receiver(undef, 0,
+ 1,1,1);
+ &debug("sending...section: $env{'request.course.sec'}");
+ foreach my $dest (keys %receivers) {
+ &debug("dest is $dest");
+ my @destinfo = split(/:/,$dest);
+ my $user = $destinfo[0];
+ my $dom = $destinfo[1];
+
+ &Apache::lonmsg::user_normal_msg($user, $dom,
+ $subject, $message);
+
+ # No point in looking at the return status as there's no good
+ # error action I can think of right now (log maybe?).
+ }
+ }
+ }
+}
+
$|=1;
-my %origENV=%ENV;
if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
print <