[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 162 - (download) (as text) (annotate)
Mon Aug 27 15:55:23 2001 UTC (11 years, 8 months ago) by sh002i
File size: 31455 byte(s)
moved $psvn_digits and $htmlModeDefault into # Internal settings #
section, changed $htmlModeDefault to HTML and $logAccessData to 0

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9