[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 322 - (download) (as text) (annotate)
Thu May 30 19:23:27 2002 UTC (17 years, 6 months ago) by gage
File size: 31656 byte(s)
Commented out use PGtranslator.

This doesn't seem to have been actually used
and it's seems to be causing  an infinite loop with WWd.pm which
calls PGtranslator, which calls Global, which calls PGtranslator.
etc.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9