[system] / trunk / webwork / system / lib / Global.pm Repository:
ViewVC logotype

View of /trunk/webwork/system/lib/Global.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (download) (as text) (annotate)
Fri Jun 15 14:29:57 2001 UTC (11 years, 11 months ago) by gage
File size: 31859 byte(s)
development version dev-1-7-01 from /ww/webwork/development 15-June-2001

    1 ### WeBWorK Version 1.6.03 1/20/01 ###
    2 use sigtrap;
    3 
    4 BEGIN {
    5 
    6   sub PG_floating_point_exception_handler {       # 1st argument is signal name
    7                 my($sig) = @_;
    8                 print "Content-type: text/html\n\n<H4>There was a floating point arithmetic error (exception SIG$sig )</H4>--perhaps
    9                 you divided by zero or took the square root of a negative number?
   10                   <BR>\n Use the back button to return to the previous page and recheck your entries.<BR>\n";
   11                 exit(0);
   12   }
   13 
   14   $SIG{'FPE'}  = \&PG_floating_point_exception_handler;
   15 
   16   sub PG_warnings_handler {
   17               my @input = @_;
   18               my $msg_string = longmess(@_);
   19               my @msg_array = split("\n",$msg_string);
   20               my $out_string = "##More details:<BR>\n----";
   21               foreach my $line (@msg_array) {
   22                 chomp($line);
   23                 next unless $line =~/\w+\:\:/;
   24                 $out_string .= "----" .$line . "<BR>\n";
   25               }
   26 
   27         $Global::WARNINGS .="*  " . join("<BR>",@input) . "<BR>\n" . $out_string .
   28                   "<BR>\n--------------------------------------<BR>\n<BR>\n";
   29         $Global::background_plain_url = $Global::background_warn_url;
   30         $Global::bg_color = '#FF99CC';  #for warnings -- this change may come too late
   31   }
   32 
   33   $SIG{__WARN__}=\&PG_warnings_handler;
   34   $SIG{__DIE__} = sub {
   35                  print "Content-type: text/html\r\n\r\n <h4>Software error</h4> @_<br>
   36                                Please inform the webwork meister.<p>
   37                                In addition to the error message above the following warnings were detected:
   38                                <HR>
   39                                $Global::WARNINGS;
   40                                <HR>
   41                                It's sometimes hard to tell exactly what has gone wrong since the
   42                                full error message may have been sent to
   43                                standard error instead of to standard out.
   44                                <p> To debug  you can
   45                                <ul>
   46                                <li> guess what went wrong and try to fix it.
   47                                <li> call the offending script directly from the command line
   48                                of unix
   49                                <li> enable the debugging features by redefining
   50                                  \$cgiURL in Global.pm and checking the redirection scripts in
   51                                  system/cgi. This will force the standard error to be placed
   52                                   in the standard out pipe as well.
   53                                <li> Run tail -f error_log <br>
   54                                    from the unix command line to see error messages from the webserver.
   55                                    The standard error output is being placed in the error_log file for the apache
   56                                    web server.  To run this command you have to be in the directory containing the
   57                                    error_log or enter the full path name of the error_log. <p>
   58                                    In a standard apache installation, this file is at /usr/local/apache/logs/error_log<p>
   59                                    In a RedHat Linux installation, this file is at /var/log/httpd/error_log<p>
   60                                    At Rochester this file is at /ww/logs/error_log.
   61                                </ul>
   62                                Good luck./n" ; exit(0); }; #exit(0);
   63 #                               CGI::Carp::croak(@_);  };
   64 #use CGI::Carp qw( fatalsToBrowser carp croak);
   65 
   66   my $CarpLevel = 0;  # How many extra package levels to skip on carp.
   67   my $MaxEvalLen = 0; # How much eval '...text...' to show. 0 = all.
   68 
   69   sub longmess {
   70     my $error = shift;
   71     my $mess = "";
   72     my $i = 1 + $CarpLevel;
   73     my ($pack,$file,$line,$sub,$eval,$require);
   74 
   75     while (($pack,$file,$line,$sub,undef,undef,$eval,$require) = caller($i++)) {
   76       if ($error =~ m/\n$/) {
   77         $mess .= $error;
   78       }
   79       else {
   80         if (defined $eval) {
   81           if ($require) {
   82             $sub = "require $eval";
   83           }
   84           else {
   85             $eval =~ s/[\\\']/\\$&/g;
   86             if ($MaxEvalLen && length($eval) > $MaxEvalLen) {
   87               substr($eval,$MaxEvalLen) = '...';
   88             }
   89             $sub = "eval '$eval'";
   90           }
   91         }
   92         elsif ($sub eq '(eval)') {
   93           $sub = 'eval {...}';
   94         }
   95 
   96         $mess .= "\t$sub " if $error eq "called";
   97         $mess .= "$error at $file line $line\n";
   98       }
   99 
  100       $error = "called";
  101     }
  102 
  103     $mess || $error;
  104   }
  105 
  106 }
  107 
  108 ###################################
  109 ## Begin Global
  110 ###################################
  111 package Global;
  112 
  113 #use CGI::Carp ; #qw( fatalsToBrowser carp croak);
  114 use PGtranslator;  # this is so that PGtranslator->evalute_macros is available when webworkCourse.ph is processed.
  115 
  116 ## $Id$
  117 
  118 # #############################################################
  119 # Copyright © 1995-2000 University of Rochester
  120 # All Rights Reserved
  121 # #############################################################
  122 
  123 
  124 
  125 ##  IMPORTANT:  The items in the section below:
  126 ##  "##These will most likely need to be customized for your site"
  127 ##  should be customized for your own site.
  128 
  129 
  130 ##  The variables defined in this package set defaults and
  131 ##  parameters for the whole weBWorK system.  Defaults can
  132 ##  be over ridden for individual courses by redefining
  133 ##  variables in the individual course webworkCourse.ph file.
  134 ##  For example the default SYSTEM feedback address set below as:
  135 ##  $feedbackAddress = 'webwork@math.rochester.edu';
  136 ##  can (and should) be over ridden for an individual course by entering e.g.
  137 ##  $Global::feedbackAdress  = 'apizer@math.rochester.edu, gage@math.rochester.edu';
  138 ##  in the individual course webworkCourse.ph file. Of course you should really
  139 ##  enter the email address(es) of the professors teaching the course.
  140 
  141 ### Private vars - refer to these as $Global::var ###
  142 
  143 ## These will most likely need to be customized for your site
  144 
  145 $feedbackAddress  = 'webwork@math.rochester.edu';
  146 $legalAddress   = '^[\w\-\.]+(\@([\w\-\.]+\.)*rochester\.edu)?$'; # destinations must match
  147 #$webmaster     = 'webmaster@math.rochester.edu';
  148 $webmaster = $feedbackAddress;
  149 #$SENDMAIL      = '/usr/sbin/sendmail -t -oi -n';  # this should no longer be needed
  150 $smtpServer     = 'mail.math.rochester.edu';
  151 $dirDelim     = '/';
  152 
  153 ## Change DBtie_file only if you want to change the default database. The script
  154 ## db_tie.pl uses DB_File (the Berkeley DB) and  gdbm_tie.pl uses GDBM_File.  This
  155 ## setting can be changed for an individual course in the webworkCourse.ph file. For
  156 ## some other database, you will have to write your own database tie-file. Such
  157 ## files reside in the scripts directory.
  158 
  159 #$DBtie_file  = 'db_tie.pl';
  160 $DBtie_file   = 'gdbm_tie.pl';
  161 
  162 ## Set to 1 to enable the access log; set to 0 to disable.
  163 ##
  164 ## The access log is stored in the logs/ directory under the system directory
  165 ## in a file called "access_log". It contains information about virtually
  166 ## every action committed by users, including all answers submitted.
  167 ## Usually this information is unneccessary, and the file becomes
  168 ## large very quickly, so this log is ordinarily turned off. However, the
  169 ## information it contains might be useful if, for example, a student wants an
  170 ## extension and claims not to have viewed the correct answers.
  171 $logAccessData = 1;
  172 
  173 ####################################################################################
  174 ########### There should be no need to customize after this point  #################
  175 ####################################################################################
  176 
  177 use diagnostics;    ## Usually this is commented out for a system students are using.
  178                     ## If you or students experience problems, uncomment this statement
  179                     ## and you will see hopefully helpful error messages.
  180 
  181 ### URL's and directory defined by the setup script system_webwork_setup.pl
  182 
  183 # for debugging uncomment the "WeBWorKCGIDebugURL" line,
  184 # comment out the "WeBWorKCGINoDebugURL" line, and edit
  185 # the wrapper scripts in the directory $cgiWebworkURL.
  186 $cgiWebworkURL = '/cgi-bin/gage_system/cgi-scripts/'; #WeBWorKCGINoDebugURL
  187 #$cgiWebworkURL = '/cgi-bin/gage_system/'; #WeBWorKCGIDebugURL
  188 # in order for system_webwork_setup.pl to set the above URLs
  189 # correctly, the comment tags must remain at the ends of
  190 # these lines.
  191 
  192 $htmlWebworkURL = '/webwork_system_html/';
  193 $mainDirectory = '/ww/webwork/gage_system/webwork/system/';
  194 
  195 
  196 ## URL's derived from above
  197 $loginURL   = "${cgiWebworkURL}login.pl";
  198 $imagesURL    = "${htmlWebworkURL}images/";
  199 $helpURL    = "${htmlWebworkURL}helpFiles/";
  200 $webworkDocsURL = 'http://webwork.math.rochester.edu/docs/docs/';
  201 $appletsURL   = "${htmlWebworkURL}applets/";
  202 
  203 
  204 require 5.000;
  205 require Exporter;
  206 @ISA = qw(Exporter);
  207 @EXPORT = qw(
  208     getWebworkScriptDirectory
  209     getWebworkCgiURL
  210     getCourseMOTDFile
  211     getSystemMOTDFile
  212     getCourseDatabaseDirectory
  213     getCourseDatabaseTieFile
  214     getCourseLogsDirectory
  215     getCourseTemplateDirectory
  216     getCourseURL
  217     getCourseScoringDirectory
  218     getCourseScriptsDirectory
  219     getCourseMacroDirectory
  220     getCourseHtmlDirectory
  221     getCourseEmailDirectory
  222     getCourseTempDirectory
  223     getCourseTempURL
  224     getCourseClasslistFile
  225     getCourseEnvironment
  226     getCourseKeyFile
  227     getCoursePasswordFile
  228     getCoursePermissionsFile
  229     getCourseDatabaseFile
  230     getCourseHtmlURL
  231     getCoursel2hDirectory
  232     getCoursel2hURL
  233     getDirDelim
  234     getDelim
  235     getScoreFilePrefix
  236     getScoring_log
  237     getDash
  238     getDat
  239     getBbext
  240     getStatusDrop
  241     convertPath
  242   getNumRelPercentTolDefault
  243   getNumZeroLevelDefault
  244   getNumZeroLevelTolDefault
  245   getNumAbsTolDefault
  246   getNumFormatDefault
  247   getFunctRelPercentTolDefault
  248   getFunctZeroLevelDefault
  249   getFunctZeroLevelTolDefault
  250   getFunctAbsTolDefault
  251   getFunctNumOfPoints
  252   getFunctVarDefault
  253   getFunctLLimitDefault
  254   getFunctULimitDefault
  255   getFunctMaxConstantOfIntegration
  256   getLoginURL
  257   getWebworkLogsDirectory
  258   wwerror
  259   getAllowDestroyRebuildProbSets
  260 );
  261 
  262 
  263 ## practice users
  264 $practiceUser = 'practice';  # name of password-less "practice" user
  265 $practiceKey  = 'practice';  # a dummy key for this user, can be anything
  266 
  267 
  268 ## The database handle for using mSQL:
  269 $dbh = 0;
  270 
  271 ## various gifs
  272 $helpGifUrl     = "${imagesURL}ww_help.gif";
  273 $logoutGifUrl   = "${imagesURL}ww_logout.gif";
  274 $feedbackGifUrl   = "${imagesURL}ww_feedback.gif";
  275 $currentImgUrl    = "${imagesURL}ww_curr.gif";
  276 $previousImgUrl   = "${imagesURL}ww_prev.gif";
  277 $nextImgUrl     = "${imagesURL}ww_next.gif";
  278 $problistImgUrl   = "${imagesURL}ww_problist.gif";
  279 $upImgUrl     = "${imagesURL}ww_up.gif";
  280 $bluesquareImgUrl = "${imagesURL}ww_bluesq.gif";
  281 $headerImgUrl   = "${imagesURL}webwork.gif";      # image to include at top of pages
  282 $squareWebworkGif = "${imagesURL}square_webwork.gif"; # image to include at top of pages
  283 
  284 ## backgrounds gifs for HTML documents
  285 $background_plain_url = "${imagesURL}white.gif";
  286 $background_okay_url  = "${imagesURL}green.gif";
  287 $background_warn_url  = "${imagesURL}red.gif";
  288 $bg_color       = '#EFEFEF';   #background color for processProblem
  289 
  290 ## Directories
  291 $coursesDirectory   = convertPath("${mainDirectory}courses/");
  292 $scriptDirectory    = convertPath("${mainDirectory}scripts/");
  293 $cgiDirectory     = convertPath("${mainDirectory}cgi/");
  294 #$tempDirectory     = convertPath("/tmp/");
  295 $authDirectory      = convertPath(".auth/");
  296 $courseScriptsDirectory = convertPath("${mainDirectory}courseScripts/");
  297 $macroDirectory     = convertPath("${mainDirectory}courseScripts/");
  298 $classDirectory     = '';  #This must be defined in webworkCourse.ph
  299 $webworkLogsDirectory = "${mainDirectory}/logs/";
  300 
  301 ## File names
  302 $coursesFilename    = 'courses-list';
  303 $coursesFile      = "${coursesDirectory}$coursesFilename";
  304 $classlistFilename    = 'classlist.lst';
  305 $keyFilename      = 'keys';
  306 $passwordFilename   = 'password';
  307 $permissionsFilename  = 'permissions';
  308 $database       = 'webwork-database';
  309 $CL_Database          =   'classlist-database';
  310 $tipsFilename     = 'tips.txt';
  311 $system_motd_filename = 'motd.txt';
  312 $course_motd_filename = 'motd.txt';
  313 $tipsFile       = "${mainDirectory}$tipsFilename";
  314 
  315 #  CGI script calls
  316 
  317 $login_CGI      = "${cgiWebworkURL}login.pl";
  318 $logout_CGI     = "${cgiWebworkURL}logout.pl";
  319 $welcome_CGI    = "${cgiWebworkURL}welcome.pl";
  320 $welcomeAction_CGI  = "${cgiWebworkURL}welcomeAction.pl";
  321 $processProblem_CGI = "${cgiWebworkURL}processProblem8.pl";
  322 $feedback_CGI   = "${cgiWebworkURL}feedback.pl";
  323 $problemEditor_CGI  = "${cgiWebworkURL}problemEditor.pl";
  324 
  325 
  326 
  327 
  328 
  329 
  330 ##  The following items control how the whole problem set is typeset by downloadPS.pl.
  331 ##  The files (e.g. "tex_set_ptramble.tex") are found in the .../templates directory
  332 ##  Note that the system dependent latex and dvips programs are defined in the file
  333 ##  makePS which is in the .../scripts directory.  makePS must be edited to call
  334 ##  the correct programs.
  335 ##
  336 
  337 ##  This is the tex preamble file used by downloadPS.pl in typeseting the whole problem set.
  338 ##  E.g. loads AMS latex and graphics packages, some macro definitions.
  339 $TEX_SET_PREAMBLE = 'texSetPreamble.tex';
  340 
  341 ##  This is the tex header file used by downloadPS.pl in typeseting the whole problem set
  342 ##  E.g. loads two column format, macro definitions.
  343 $TEX_SET_HEADER = '';
  344 
  345 ##  This is the header file used by downloadPS.pl to enter preliminary verbiage for the
  346 ##  whole problem set. E.g. Course name, student name, problem set number,instructions, due date.
  347 $SET_HEADER = 'paperSetHeader.pg';
  348 
  349 ##  This is the tex footer file used by downloadPS.pl in typeseting the whole problem set
  350 $TEX_SET_FOOTER = 'texSetFooter.tex';
  351 
  352 
  353 ##  The following items control how an individual problem is typeset by processProblem.pl
  354 ##  and l2h.  Note that the system dependent latex2html program is defined in processProblem.pl.  It
  355 ##  should really be in a seperate file like makeps.
  356 
  357 ##  This is the tex preamble file used by processProblem.pl typeseting an individual problem
  358 ##  Usually very similar to $TEX_SET_PREAMBLE
  359 $TEX_PROB_PREAMBLE = 'texProbPreamble.tex';
  360 
  361 ##  This is the tex header file used by processProblem.pl typeseting an individual problem
  362 $TEX_PROB_HEADER = '';
  363 
  364 
  365 ##  This is the header file used by probSet.pl to enter preliminary verbiage on the prob set
  366 ##  page. E.g. Instructions, due date.
  367 $PROB_HEADER = 'screenSetHeader.pg';
  368 
  369 ##  This is the tex footer file processProblem.pl typeseting an individual problem
  370 $TEX_PROB_FOOTER = 'texProbFooter.tex';
  371 
  372 
  373 
  374 $courseEnvironmentFile  = 'webworkCourse.ph';
  375 #$webworkCourse_ph    = 'webworkCourse.ph';
  376 $DBglue_pl        = 'DBglue8.pl';
  377 $HTMLglue_pl      = 'HTMLglue.pl';
  378 $classlist_DBglue_pl  = 'classlist_DBglue.pl';
  379 $FILE_pl        = 'FILE.pl';
  380 $displayMacros_pl   = 'displayMacros.pl';
  381 $scoring_log      = 'scoring.log';
  382 #####$probSetHeader   = 'probSetHeader';
  383 $SCRtools_pl      = 'pScSet6.pl';
  384 $buildProbSetTools    = 'proceduresForBuildProbSetDB.pl';
  385 
  386 
  387 ## File and Directory permissions
  388 
  389 ## e.g. S1-1521.sco in (base course directory)/DATA
  390 $sco_files_permission = 0660;
  391 
  392 ## tie permissions (used in tie commands)
  393 ## The database, password, and permissions files
  394 ## always take their permissions from the Global
  395 ## vaiables below.  The important keys file
  396 ## takes its permission from $restricted_tie_permission.
  397 $restricted_tie_permission = 0600;
  398 $standard_tie_permission = 0660;
  399 
  400 ## webwork-database in (base course directory)/DATA
  401 $webwork_database_permission = 0660;
  402 
  403 ## password in (base course directory)/DATA/.auth
  404 $password_permission = 0660;
  405 
  406 ## permissions in (base course directory)/DATA/.auth
  407 $permissions_permission = 0660;
  408 
  409 ## e.g. s1ful.csv in (base course directory)/scoring
  410 $scoring_files_permission = 0660;
  411 
  412 ## e.g. s1bak1.csv in (base course directory)/scoring
  413 $scoring_bak_files_permission = 0440;
  414 
  415 ## e.g. 8587l2h.log  in (base course directory)/html/tmp/l2h
  416 $l2h_logs_permission = 0660;
  417 
  418 ## e.g. set1/ in (base course directory)/html/tmp/l2h
  419 $l2h_set_directory_permission = 0770;
  420 
  421 ## e.g. 1-1082/ in (base course directory)/html/tmp/l2h/set1
  422 $l2h_prob_directory_permission  = 0770;
  423 
  424 ## e.g. 1082output.html in (base course directory)/html/tmp/l2h/set1/1-1082
  425 $l2h_data_permission = 0770;
  426 
  427 ## e.g. file.gif in (base course directory)/html/tmp/gif
  428 $tmp_file_permission = 0660;
  429 
  430 ## e.g. gif/ in (base course directory)/html/tmp/
  431 $tmp_directory_permission = 0770;
  432 
  433 ##e.g. classlist files (e.g. MTH140A.lst) in (base course directory)/templates/
  434 $classlist_file_permission = 0660;
  435 
  436 
  437 
  438 ##   Prefixes, extensions, defaults, etc
  439 
  440 
  441 
  442 $scoreFilePrefix    = 'S';
  443 $dash         = '-';  # Can not be the underscore character or an upper or
  444                 # lowercase letter or a digit. Used in .sco file names
  445 $delim          = ',';  # used in scoring, classlist
  446 $dat          = 'csv';
  447 @statusDrop       = qw(drop d withdraw);
  448 $courselist_delim   = '::'; # used by login.pl to get course names / dirs
  449 $instructor_permissions = 10;
  450 $TA_permissions     = 5;
  451 $psvn_digits      = 5;    # Number of digits in psvn numbers. E.g. if 4, psvn's
  452                   # will be between 1000 and 9999. The number of available
  453                   # psvn's must be greater than (#students)*(#problem sets)
  454 $score_decimal_digits = 1;    # Number of decimal digits in recorded scores. For example
  455                   # if this is 1 then on a 1 point problem that allows partial
  456                   # credit, possible scores are 0, .1, .2, ..., 1.
  457 
  458 $maxAttemptsWarningLevel = 5;
  459                         # If the set definition file puts a limit on the number of
  460                         # times a problem may be attempted, processProblem.pl will
  461                         # give a warning message when <= $maxAttemptsWarningLevel
  462                         # attempts remain.
  463 
  464 $noOfFieldsInClasslist = 9;
  465                         # The number of fields in the classlist file. This is used as
  466                         # a check to make sure each record in the classlist file has
  467                         # this number of fields
  468 
  469 $htmlModeDefault = 'HTML_tth';    # The default mode for displayed problems (either 'HTML',
  470                               # 'Latex2HTML', or 'HTML_tth'
  471 
  472 $allowStudentToChangeEMAddress = 1; # setting to 1 allows students to change their
  473                                     # own email address. Setting to 0 disallows this
  474 
  475 $Global::PG_environment{showPartialCorrectAnswers} = 1;  ## Set to 0 or 1. If set to 1 in multipart
  476                                     # questions the student will be told which parts are
  477                                     # correct and which are incorrect.  Usually, this is
  478                                     # set explicitly in each individual problem.
  479 
  480 $allowDestroyRebuildProbSets = 0;   # Set to 0 or 1. If set to 1 a professor can destroy and
  481                                     # rebuild problems sets in one operation. This is very
  482                                     # convenient and powerful, but also very dangerous.  Usually
  483                                     # this is not allowed in courses students are using.  It is
  484                                     # often set to 1 in a private course being used only for
  485                                     # developing problem sets.  To do this, reset this in the
  486                                     # private course's webworkCourse.ph file.
  487 
  488 $Global::PG_environment{recordSubmittedAnswers} = 1;  # Set to 0 or 1. If set to 1, submitted answers will be
  489                   # stored. For example in a multipart question, a student can
  490                   # do several parts, then logout or go onto another question.
  491                   # When they view the problem again, the answer blanks will be
  492                   # filled in with their most recent answers. This also allows
  493                   # professors to see exactly what a student entered. This default
  494                   # can be over ridden for an individual problem by setting
  495                   # recordSubmittedAnswers in the .pg file for the problem.
  496 
  497 $maxSizeRecordedAns = 256;      # Student answers longer than this length in bytes will not
  498                   # stored in the database.
  499 
  500 $hide_studentID_from_TAs = 0;     # Set to 0 or 1. If set to 1, studentID's will be hidden
  501                   # from TA's.  For example some Universities may use SS#'s for
  502                   # student ID's and you may not want TA's to view these.
  503 
  504 ## arguments for flock()
  505 
  506 $shared_lock      = 1;
  507 $exclusive_lock   = 2;
  508 $nonblocking_lock = 4;
  509 $unlock_lock      = 8;
  510 
  511 # These values provide defaults for the various answer comparison macros found
  512 # in PGanswermacros.pl.  They can be over ridden for individual courses by
  513 # redefining the variables in the individual course webworkCourse.ph file.
  514 # They can be over ridden for individual problems by explicitly passing the
  515 # desired values to the answer comparison macro
  516 
  517 # The following effect numerical answer comparison
  518 $numRelPercentTolDefault  = .1;
  519 $numZeroLevelDefault    = 1E-14;
  520 $numZeroLevelTolDefault   = 1E-12;
  521 $numAbsTolDefault     = .001;
  522 $numFormatDefault     = '';   ## use perl's format in prfmt()
  523 # The following effect function comparison
  524 $functRelPercentTolDefault  = .1;
  525 $functZeroLevelDefault    = 1E-14;
  526 $functZeroLevelTolDefault = 1E-12;
  527 $functAbsTolDefault     = .001;
  528 $functNumOfPoints     = 3;
  529 $functVarDefault      = 'x';
  530 $functLLimitDefault     = .0000001;
  531 $functULimitDefault     = .9999999;
  532 # The following effects function comparison upto constant for antidifferentiation
  533 $functMaxConstantOfIntegration = 1E8;
  534 
  535 ## These values provide defaults for the window size in the problemEditor.pl script
  536 $editor_window_rows   = 25;
  537 $editor_window_columns  = 90;
  538 
  539 ## This is the maximum number problems sets that can be downloaded at one time
  540 ## by a professor.  Set this higher or lower depending on the speed of your server
  541 
  542 $max_num_of_ps_downloads_allowed = 20;
  543 
  544 
  545 # Subroutines for defining the directories and URLs
  546 ###### Public vars/routines - these are imported into your namespace, #######
  547 ###### so they can be called as they are.
  548                   #######
  549 
  550 sub getWebworkScriptDirectory { convertPath($scriptDirectory )  };
  551 sub getCourseDatabaseDirectory  { convertPath($databaseDirectory )};
  552 sub getCourseDatabaseTieFile  { convertPath($DBtie_file )};
  553 sub getCourseLogsDirectory    { convertPath($logsDirectory )};
  554 sub getCourseTemplateDirectory  { convertPath($templateDirectory )};
  555 sub getCourseEmailDirectory     { convertPath("${templateDirectory}email/")};
  556 sub getCourseScoringDirectory { convertPath($scoringDirectory ) };
  557 sub getCourseHtmlDirectory    { convertPath($htmlDirectory )};
  558 sub getCourseTempDirectory    {convertPath($courseTempDirectory)};
  559 sub getCoursel2hDirectory   { convertPath( "${courseTempDirectory}l2h/" )};
  560 sub getCourseScriptsDirectory { convertPath($courseScriptsDirectory  )};
  561 sub getCourseMacroDirectory   { convertPath($macroDirectory  )};
  562 sub getWebworkLogsDirectory   { convertPath($webworkLogsDirectory)};
  563 
  564 sub getCourseClasslistFile    { convertPath("${coursesDirectory}$_[0]/templates/${classlistFilename}") };
  565 
  566 sub getCourseKeyFile      { convertPath("${coursesDirectory}$_[0]/DATA/${authDirectory}${keyFilename}") };
  567 sub getCoursePasswordFile   { convertPath("${coursesDirectory}$_[0]/DATA/${authDirectory}${passwordFilename}") };
  568 sub getCoursePermissionsFile  { convertPath("${coursesDirectory}$_[0]/DATA/${authDirectory}${permissionsFilename}") };
  569 sub getCourseDatabaseFile     { convertPath("${coursesDirectory}$_[0]/DATA/${$database}") };
  570 
  571 sub getCourseMOTDFile       { convertPath("${coursesDirectory}$_[0]/templates/${course_motd_filename}") };
  572 sub getSystemMOTDFile       { convertPath("${mainDirectory}${system_motd_filename}") };
  573 
  574 sub getWebworkCgiURL  { $cgiWebworkURL };
  575 sub getCourseHtmlURL  { $htmlURL };
  576 sub getCoursel2hURL   { "${courseTempURL}l2h/" }
  577 sub getCourseTempURL  { $courseTempURL };   #defined in webworkCourse.ph
  578 sub getDirDelim     { $dirDelim };
  579 sub getDelim      { $delim };
  580 sub getScoreFilePrefix  { $scoreFilePrefix };
  581 sub getScoring_log    { $scoring_log };
  582 sub getDash       { $dash };
  583 sub getDat        { $dat };
  584 sub getBbext      { @dbext };
  585 sub getStatusDrop   { @statusDrop };
  586 
  587 sub  getNumRelPercentTolDefault     { $numRelPercentTolDefault };
  588 sub  getNumZeroLevelDefault       { $numZeroLevelDefault };
  589 sub  getNumZeroLevelTolDefault      { $numZeroLevelTolDefault };
  590 sub  getNumAbsTolDefault        { $numAbsTolDefault };
  591 sub  getNumFormatDefault        { $numFormatDefault };
  592 sub  getFunctRelPercentTolDefault   { $functRelPercentTolDefault };
  593 sub  getFunctZeroLevelDefault     { $functZeroLevelDefault };
  594 sub  getFunctZeroLevelTolDefault    { $functZeroLevelTolDefault };
  595 sub  getFunctAbsTolDefault        { $functAbsTolDefault };
  596 sub  getFunctNumOfPoints        { $functNumOfPoints };
  597 sub  getFunctVarDefault         { $functVarDefault };
  598 sub  getFunctLLimitDefault        { $functLLimitDefault };
  599 sub  getFunctULimitDefault        { $functULimitDefault };
  600 sub  getFunctMaxConstantOfIntegration { $functMaxConstantOfIntegration };
  601 
  602 sub  getLoginURL  { $loginURL };
  603 
  604 sub  getAllowDestroyRebuildProbSets { $allowDestroyRebuildProbSets };
  605 
  606 sub getCourseEnvironment {
  607     die "getCourseEnvironment was called without specifying a course" unless $_[0];
  608   my $fullPath = convertPath("${coursesDirectory}$_[0]/$courseEnvironmentFile");
  609     require "$fullPath"
  610         || die "Can't find local environment file for
  611                  $fullPath\n";
  612 }
  613 
  614 
  615 
  616 ### dump a (hopefully) descriptive error to the browser and quit
  617 #sub wwerror {
  618 #    my($title, $msg, $url, $label, $query_string) = @_;
  619 #
  620 #    print "content-type: text/html\n\n
  621 #          <HTML><HEAD><TITLE>Error: $title</TITLE></HEAD>
  622 #          <BODY BACKGROUND=\"$background_warn_url\">
  623 #          <H1>Error: $title</H1>\n $msg \n";
  624 #    if ($url) {
  625 #    print "<FORM ACTION=\"$url\">
  626 #           <INPUT TYPE=SUBMIT VALUE=\"$label\">
  627 #           </FORM>\n";
  628 #    }
  629 #    print "</BODY></HTML>";
  630 #    &log_error($title, $query_string);
  631 #    exit 1;
  632 #}
  633 
  634 sub wwerror {
  635     my($title, $msg, $url, $label, $query_string) = @_;
  636     # <BODY BACKGROUND=\"$background_warn_url\">
  637 
  638     $msg = '' unless defined $msg;
  639     $url = '' unless defined $url;
  640     $label = '' unless defined $label;
  641     $query_string = '' unless defined $query_string;
  642 
  643     print "content-type: text/html\n\n
  644           <HTML><HEAD><TITLE>Error: $title</TITLE></HEAD>
  645           <BODY BGCOLOR = 'CCCCCC'>
  646 
  647           <H2>Error: $title</H2>
  648           <PRE>$msg\n
  649           </PRE>";
  650     if ($url) {
  651     print "<FORM ACTION=\"$url\">
  652            <INPUT TYPE=SUBMIT VALUE=\"$label\">
  653            </FORM>\n";
  654     }
  655     print "</BODY></HTML>";
  656     &log_error($title, $query_string);
  657     exit 1;
  658 }
  659 
  660 sub error {wwerror(@_);}        ##alias for wwerror
  661 
  662 
  663 # return a (scalar) tip
  664 sub tip {
  665     my ($tips, @tiplist);
  666     local($/) = undef;
  667     #undef $/; # slurp it all in
  668     open(TIPS, "$tipsFile") || &error("Can't open $tipsFile");
  669     $tips = <TIPS>;
  670     close(TIPS);
  671 
  672     # add any local tips to the list before we pick a random one
  673     if (-r "${templateDirectory}$tipsFilename") {
  674         open(TIPS, "${templateDirectory}$tipsFilename");
  675         $tips .= '%%' . <TIPS>;
  676         close(TIPS);
  677     }
  678     $/ = "\n"; # <> now reads until newline
  679     $tips =~ s/#.*?\n//mg;  # remove comments
  680     @tiplist = split(/%%/, $tips);
  681     return $tiplist[rand(@tiplist)];    # choose one at random
  682 }
  683 
  684 # return an array of tips
  685 sub all_tips {
  686     my ($tip, $tips, @tiplist);
  687 
  688     local($/) = undef; # slurp it all in
  689     open(TIPS, "$tipsFile") || &error("Can't open $tipsFile");
  690     $tips = <TIPS>;
  691     close(TIPS);
  692 
  693     # add any local tips to the list before we pick a random one
  694     if (-r "${templateDirectory}$tipsFilename") {
  695         open(TIPS, "${templateDirectory}$tipsFilename");
  696         $tips .= '%%' . <TIPS>;
  697         close(TIPS);
  698     }
  699     $/ = "\n"; # <> now reads until newline
  700     $tips =~ s/#.*?\n//mg;  # remove comments
  701     @tiplist = split(/%%/, $tips);
  702     return @tiplist;
  703 }
  704 
  705 
  706 # begin Timing code
  707 use Benchmark;
  708 sub dateTime {
  709     my @timeArray = localtime(time);
  710     my $out = sprintf("%2.2d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
  711     $timeArray[5],$timeArray[4]+1,@timeArray[3,2,1,0]);
  712     $out;
  713 }
  714 
  715 #the ps system calls do not work on all systems, and are usually not
  716 #necessary anyway. If you wish that information to be logged, simply
  717 #uncomment the relevant lines, but be warned that they might need to
  718 #be modified for your system
  719 sub logTimingInfo {
  720     my ($beginTime,$endTime,$script,$course,$user,$remoteHost,$userAgent) = @_;
  721     $remoteHost = ""unless defined($remoteHost);
  722     $userAgent  = ""   unless defined($userAgent);
  723     open(TIMELOG, ">>${webworkLogsDirectory}timing_log") ||
  724       warn "*Unable to open timing log for writing:\n ${webworkLogsDirectory}timing_log. ";
  725 
  726   my $mem_string = '';
  727 #     my $process_string = `ps -o vsz -p $$`;
  728 #     $process_string =~ s/^\s*//;
  729 #     $process_string =~ s/\s*$//;
  730 #     my @process_string = split(/\s+/,$process_string);  # gets memory size
  731 #     my $mem_string = " mem: ${process_string[1]}K";
  732 
  733   my $load_string = '';
  734 #     my @load = split(/\n/,`ps -U wwhttpd -o state`);
  735 #     my $load_string = " load: " . grep(/R/,@load);
  736 
  737     print TIMELOG $script,"\t",$course,"\t",&dateTime,"\t",
  738                   timestr( timediff($endTime,$beginTime), 'all' ),"\t",
  739                   "pid: $$ DBtie_tries: $Global::DBtie_tries" . $mem_string . $load_string,"\t",$user,"\t",
  740                   $remoteHost,"\t",$userAgent,"\n";
  741     close(TIMELOG);
  742 }
  743 # end Timing code
  744 
  745 
  746 # handy routines for modules that wish to throw exceptions outside of the
  747 # current package. (taken from Carp.pm)
  748 #
  749 # We'll want to remove this in final versions of WeBWorK.
  750 
  751 sub log_error {
  752     my ($comment, $data) = @_;
  753     my $accessLog = convertPath("${webworkLogsDirectory}access_log");
  754     my $errorLog = convertPath("${webworkLogsDirectory}error_log");
  755     open(ACCESS, ">>$accessLog");
  756     open(ERROR, ">>$errorLog");
  757     print ACCESS "ERROR ($comment) ", scalar(localtime), ': ', &shortmess($data);
  758     print ERROR "ERROR ($comment) ", scalar(localtime), ': ', &shortmess($data);
  759     close(ACCESS);
  760     close(ERROR);
  761 }
  762 
  763 sub log_info {
  764     if( $Global::logAccessData == 1 ) {
  765     my ($comment, $data) = @_;
  766       my $accessLog = convertPath("${webworkLogsDirectory}access_log");
  767       open(LOG, ">>$accessLog") or warn "Can't open accessLog $accessLog";
  768       print LOG "INFO ($comment) ", scalar(localtime), ': ',  &shortmess($data);
  769       close(LOG);
  770   }
  771 }
  772 
  773 
  774 ## converts full path names to to use the $dirDelim instead of /
  775 sub convertPath {
  776     my ($path) = @_;
  777     warn "convertPath has been asked to convert an empty path<BR> |$path| at ", caller(),"<BR>" unless $path;
  778     $path =~ s|/|$dirDelim|g;
  779 
  780   $path;
  781 }
  782 
  783 ###############
  784 ## Error message routines
  785 ###############
  786 
  787 BEGIN {    #error message routines
  788 
  789   my $CarpLevel = 0;  # How many extra package levels to skip on carp.
  790   my $MaxEvalLen = 0; # How much eval '...text...' to show. 0 = all.
  791 
  792   sub longmess {
  793     my $error = shift;
  794     my $mess = "";
  795     my $i = 1 + $CarpLevel;
  796     my ($pack,$file,$line,$sub,$eval,$require);
  797 
  798     while (($pack,$file,$line,$sub,undef,undef,$eval,$require) = caller($i++)) {
  799       if ($error =~ m/\n$/) {
  800         $mess .= $error;
  801       }
  802       else {
  803         if (defined $eval) {
  804           if ($require) {
  805             $sub = "require $eval";
  806           }
  807           else {
  808             $eval =~ s/[\\\']/\\$&/g;
  809             if ($MaxEvalLen && length($eval) > $MaxEvalLen) {
  810               substr($eval,$MaxEvalLen) = '...';
  811             }
  812             $sub = "eval '$eval'";
  813           }
  814         }
  815         elsif ($sub eq '(eval)') {
  816           $sub = 'eval {...}';
  817         }
  818 
  819         $mess .= "\t$sub " if $error eq "called";
  820         $mess .= "$error at $file line $line\n";
  821       }
  822 
  823       $error = "called";
  824     }
  825 
  826     $mess || $error;
  827   }
  828 
  829   sub shortmess { # Short-circuit &longmess if called via multiple packages
  830     my $error = $_[0];  # Instead of "shift"
  831     my ($curpack) = caller(1);
  832     my $extra = $CarpLevel;
  833     my $i = 2;
  834     my ($pack,$file,$line);
  835 
  836     while (($pack,$file,$line) = caller($i++)) {
  837       if ($pack ne $curpack) {
  838         if ($extra-- > 0) {
  839           $curpack = $pack;
  840         }
  841         else {
  842           return "$error at $file line $line\n";
  843         }
  844       }
  845     }
  846 
  847     goto &longmess;
  848   }
  849 
  850 
  851 }
  852 
  853 
  854 
  855 
  856 ###############
  857 ## End Error message routines
  858 ###############
  859 
  860 
  861 1;  ## This line is required by perl

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9