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 / addknowncourse.js < prev    next >
Encoding:
Text File  |  2004-07-12  |  3.6 KB  |  107 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 addknowncourse.js" )
  27.  
  28. // Retrieve things from the session and request
  29. // NOTE: they are all of type java.lang.String
  30.  
  31. session     = request.getSession( false )
  32. uwid         = session.getAttribute( "uwid" )
  33. term         = request.getParameter( "term" )
  34. course         = request.getParameter( "course" )
  35. distanceEd     = request.getParameter( "distanceEd" )
  36. extra         = request.getParameter( "extra" )
  37.  
  38. logger.debug( "Raw" )
  39. logger.debug( "  uwid          [" + uwid + "]" )
  40. logger.debug( "  term          [" + term + "]" )
  41. logger.debug( "  course        [" + course + "]" )
  42. logger.debug( "  distanceEd    [" + distanceEd + "]" )
  43. logger.debug( "  extra         [" + extra + "]" )
  44.  
  45. // Cook things a little to make them palatable to the database
  46.  
  47. if ( term == "0" ) { term = "" }
  48. if ( course == "0" ) { course = "" }
  49. if ( distanceEd == "on" ) { distanceEd = 2 } else { distanceEd = 1 }
  50. if ( extra == "on" ) { extra = 2 } else { extra = 1 }
  51.  
  52. logger.debug( "Cooked" )
  53. logger.debug( "  uwid          [" + uwid + "]" )
  54. logger.debug( "  term          [" + term + "]" )
  55. logger.debug( "  course        [" + course + "]" )
  56. logger.debug( "  distanceEd    [" + distanceEd + "]" )
  57. logger.debug( "  extra         [" + extra + "]" )
  58.  
  59. // Actually do the database work
  60.  
  61. // We have the choice of declaring things out here and making them explicitly
  62. // null, or we have to use a different comparison in the "finally" block (defined?)
  63.  
  64. dbselector = null
  65. datasource = null
  66. conn = null
  67. addStatement = null
  68.  
  69. try
  70. {
  71.     dbselector = manager.lookup( scriptaction.DB_CONNECTION )
  72.     datasource = dbselector.select( "ceabplanner" )
  73.     conn = datasource.getConnection()    
  74.     addStatement = conn.prepareStatement(
  75.     "INSERT INTO studentKnownCourseList ( STUDENT, KNOWN_COURSE, TERM_TAKEN, DISTANCE_ED, COURSE_EXTRA)" +
  76.     "VALUES  ( ( SELECT id FROM students WHERE uw_userid = ? ), ?, ?, ?, ? )"
  77.     )
  78.     
  79.     addStatement.setString( 1, uwid ); 
  80.     addStatement.setString( 2, course ); 
  81.     addStatement.setString( 3, term ); 
  82.     addStatement.setString( 4, distanceEd ); 
  83.     addStatement.setString( 5, extra ); 
  84.     
  85.     result = addStatement.executeUpdate()
  86.     logger.debug( "Result #1 [" + result + "]" )
  87.     
  88.     conn.commit()
  89.     
  90.     actionMap.put( "scriptaction-continue", "" )
  91.     session.setAttribute( "results", "<SUCCESS>Course added at " + Date() + "</SUCCESS>" )    
  92. }
  93. catch( ex )
  94. {
  95.     logger.debug( "Caught Exception" )
  96.     logger.debug( "  " + ex )
  97. }
  98. finally
  99. {
  100.     if ( null != addStatement ) { addStatement.close() }
  101.     if ( null != conn ) { conn.close() }
  102.     if ( null != datasource ) { dbselector.release( datasource ) }
  103.     if ( null != dbselector ) { manager.release( dbselector ) }
  104. }
  105.  
  106. logger.debug( "END addknown.js" )
  107.