home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / addunknownte.js < prev    next >
Encoding:
Text File  |  2004-07-12  |  6.9 KB  |  195 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // Step 1 -- Retrieve helper "beans" from the BSF framework
  17.  
  18. scriptaction = bsf.lookupBean( "scriptaction" )
  19. manager      = bsf.lookupBean( "manager" )            
  20. request      = bsf.lookupBean( "request" )
  21. logger       = bsf.lookupBean( "logger" )
  22. actionMap    = bsf.lookupBean( "actionMap" )
  23.  
  24. // Step 2 -- Perform the action
  25.  
  26. logger.debug( "START addunknownte.js" )
  27.  
  28. csetype = ""
  29. weight = 0
  30.  
  31. lectureHrs = 3
  32. labHrs = 0
  33. tutorialHrs = 0
  34. numWeeks = 12
  35.  
  36. courseWeight = 0
  37. mathWeight = 0
  38. sciWeight = 0
  39. engsciWeight = 0
  40. engdesWeight = 0
  41.  
  42. mathWt = 0
  43. sciWt = 0
  44. engsciWt = 0
  45. engdesWt = 0
  46.  
  47. // Retrieve things from the session and request
  48. // NOTE: they are all of type java.lang.String
  49.  
  50. session    = request.getSession( false )
  51. uwid       = session.getAttribute( "uwid" )
  52. term       = request.getParameter( "term" )
  53. dept       = request.getParameter( "dept" )
  54. number     = request.getParameter( "number" )
  55. letter     = request.getParameter( "letter" )
  56. name       = request.getParameter( "name" )
  57. lectures   = request.getParameter( "lectures" )
  58. labs       = request.getParameter( "labs" )
  59. tutorials  = request.getParameter( "tutorials" )
  60. weeks      = request.getParameter( "weeks" )
  61. math       = request.getParameter( "math" )
  62. sci        = request.getParameter( "sci" )
  63. engsci     = request.getParameter( "engsci" )
  64. engdes     = request.getParameter( "engdes" )
  65. distanceEd = request.getParameter( "distanceEd" )
  66. extra      = request.getParameter( "extra" )
  67.  
  68. logger.debug( "Raw" )
  69. logger.debug( "  uwid          [" + uwid + "]" )
  70. logger.debug( "  term          [" + term + "]" )
  71. logger.debug( "  dept          [" + dept + "]" )
  72. logger.debug( "  number        [" + number + "]" )
  73. logger.debug( "  letter        [" + letter + "]" )
  74. logger.debug( "  name          [" + name + "]" )
  75. logger.debug( "  lectures      [" + lectures + "]" )
  76. logger.debug( "  labs          [" + labs + "]" )
  77. logger.debug( "  tutorials     [" + tutorials + "]" )
  78. logger.debug( "  weeks         [" + weeks + "]" )
  79. logger.debug( "  math          [" + math + "]" )
  80. logger.debug( "  sci           [" + sci + "]" )
  81. logger.debug( "  engsci        [" + engsci + "]" )
  82. logger.debug( "  engdes        [" + engdes + "]" )
  83. logger.debug( "  distanceEd    [" + distanceEd + "]" )
  84. logger.debug( "  extra         [" + extra + "]" )
  85. logger.debug( "  courseWeight  [" + courseWeight + "]" )
  86. logger.debug( "  mathWt        [" + mathWt + "]" )
  87. logger.debug( "  sciWt         [" + sciWt + "]" )
  88. logger.debug( "  engsciWt      [" + engsciWt + "]" )
  89. logger.debug( "  engdesWt      [" + engdesWt + "]" )
  90.  
  91. // Cook things a little to make them palatable to the database
  92.  
  93. if (lectures != null) { lectureHrs = ( lectures + "" ) }
  94. if (labs != null) { labHrs = ( labs + "" ) }
  95. if (tutorials != null) { tutorialHrs = ( tutorials + "" ) }
  96. if (weeks != null) { numWeeks = ( weeks + "" ) }
  97.  
  98. if (math != null) { mathWeight = ( math + "" ) }
  99. if (sci != null) { sciWeight = ( sci + "" ) }
  100. if (engsci != null) { engsciWeight = ( engsci + "" ) }
  101. if (engdes != null) { engdesWeight = ( engdes + "" ) }
  102.  
  103. // The "/1" is vital to ensure a numeric context
  104.  
  105. courseWeight=(((lectureHrs/1)+(labHrs/2)+(tutorialHrs/2))*numWeeks)
  106. mathWt = courseWeight*mathWeight
  107. sciWt = courseWeight*sciWeight
  108. engsciWt = courseWeight*engsciWeight
  109. engdesWt = courseWeight*engdesWeight
  110.  
  111. if ( distanceEd == "on" ) { distanceEd = 2 } else { distanceEd = 1 }
  112. if ( extra == "on" ) { extra = 2 } else { extra = 1 }
  113.  
  114. logger.debug( "Cooked" )
  115. logger.debug( "  uwid          [" + uwid + "]" )
  116. logger.debug( "  term          [" + term + "]" )
  117. logger.debug( "  dept          [" + dept + "]" )
  118. logger.debug( "  number        [" + number + "]" )
  119. logger.debug( "  letter        [" + letter + "]" )
  120. logger.debug( "  name          [" + name + "]" )
  121. logger.debug( "  lectures      [" + lectures + "]" )
  122. logger.debug( "  labs          [" + labs + "]" )
  123. logger.debug( "  tutorials     [" + tutorials + "]" )
  124. logger.debug( "  weeks         [" + weeks + "]" )
  125. logger.debug( "  math          [" + math + "]" )
  126. logger.debug( "  sci           [" + sci + "]" )
  127. logger.debug( "  engsci        [" + engsci + "]" )
  128. logger.debug( "  engdes        [" + engdes + "]" )
  129. logger.debug( "  distanceEd    [" + distanceEd + "]" )
  130. logger.debug( "  extra         [" + extra + "]" )
  131. logger.debug( "  courseWeight  [" + courseWeight + "]" )
  132. logger.debug( "  mathWt        [" + mathWt + "]" )
  133. logger.debug( "  sciWt         [" + sciWt + "]" )
  134. logger.debug( "  engsciWt      [" + engsciWt + "]" )
  135. logger.debug( "  engdesWt      [" + engdesWt + "]" )
  136.  
  137. // Actually do the database work
  138.  
  139. // We have the choice of declaring things out here and making them explicitly
  140. // null, or we have to use a different comparison in the "finally" block (defined?)
  141.  
  142. dbselector = null
  143. datasource = null
  144. conn = null
  145. addStatement = null
  146.  
  147. try
  148. {
  149.     dbselector = manager.lookup( scriptaction.DB_CONNECTION )
  150.     datasource = dbselector.select( "ceabplanner" )
  151.     conn = datasource.getConnection()    
  152.     addStatement = conn.prepareStatement(
  153.        "INSERT INTO otherCourses( " +
  154.          "ID, STUDENT, DEPARTMENT, COURSENUMBER, COURSELETTER, COURSENAME, MATH, SCI, ENGSCI, ENGDES,  TERM_TAKEN, DISTANCE_ED, COURSE_EXTRA, CSEWEIGHT)" +
  155.        "VALUES  ( " +
  156.          "otherCourses_seq.nextval, ( SELECT id FROM students WHERE uw_userid = ? ), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)"
  157.     )
  158.  
  159.     addStatement.setString( 1, uwid ); 
  160.     addStatement.setString( 2, dept ); 
  161.     addStatement.setString( 3, number ); 
  162.     addStatement.setString( 4, letter ); 
  163.     addStatement.setString( 5, name ); 
  164.     addStatement.setString( 6, mathWt ); 
  165.     addStatement.setString( 7, sciWt ); 
  166.     addStatement.setString( 8, engsciWt ); 
  167.     addStatement.setString( 9, engdesWt ); 
  168.     addStatement.setString( 10, term ); 
  169.     addStatement.setString( 11, distanceEd ); 
  170.     addStatement.setString( 12, extra ); 
  171.  
  172.     result = addStatement.executeUpdate()
  173.     logger.debug( "Result #1 [" + result + "]" )
  174.  
  175.     conn.commit()
  176.  
  177.     actionMap.put( "scriptaction-continue", "" )
  178.     session.setAttribute( "results", "<SUCCESS>Unknown Technical Elective added at " + Date() + "</SUCCESS>" )
  179.  
  180. }
  181. catch( ex )
  182. {
  183.     logger.debug( "Caught Exception" )
  184.     logger.debug( "  " + ex )
  185. }
  186. finally
  187. {
  188.     if ( null != addStatement ) { addStatement.close() }
  189.     if ( null != conn ) { conn.close() }
  190.     if ( null != datasource ) { dbselector.release( datasource ) }
  191.     if ( null != dbselector ) { manager.release( dbselector ) }
  192. }
  193.  
  194. logger.debug( "END addunknownte.js" )
  195.