linker.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Sloodle PrimDrop linker (for Sloodle 0.3).
  4. * Allows a Sloodle PrimDrop object to interact with a 'Sloodle Object' assignment type.
  5. *
  6. * @package sloodleprimdrop
  7. * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  8. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. * @contributor Jeremy Kemp
  11. * @contributor Peter R. Bloomfield
  12. */
  13. // This script should be called with the following parameters:
  14. // sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  15. // sloodlepwd = the prim password or object-specific session key to authenticate the request
  16. // sloodlemoduleid = cmID of an assignment
  17. //
  18. // If accessed with only the above paramters, then the script will return information about the assignment.
  19. // Status code will be 1, and the first data line will contain the name of the assignment.
  20. // The second data line will contain the description of the assignment.
  21. //
  22. // To check whether or not a user can submit an assignment, the following details should also be provided:
  23. // sloodleuuid = UUID of the avatar who created the submission
  24. // sloodleavname = name of the avatar who created the submission
  25. //
  26. // The status code returned will be as follows (no data):
  27. // 1 = OK
  28. // -10201 = User is not authorised to submit assignments
  29. // -10202 = Assignment is not yet open for submissions
  30. // -10203 = Assignment due date has passed, and is closed for submissions
  31. // -10204 = Assignment due date has passed, but is still accepting submissions
  32. // -10205 = User has already submitted, and resubmissions are not being accepted
  33. //
  34. // To report a submission, the following parameters (in addition to all above) should be provided:
  35. // sloodleobjname = Name of the object being submitted
  36. // sloodleprimcount = Number of prims in the object being submitted
  37. // sloodleprimdropname = Name of the PrimDrop object being submitted to
  38. // sloodleprimdropuuid = UUID of the PrimDrop object being submitted to
  39. // sloodleregion = region in which the PrimDrop is located
  40. // sloodlepos = position of the PrimDrop (vector <x,y,z>)
  41. //
  42. // If the submission was successful, the status code will be 1.
  43. // Otherwise, the codes above may be returned (although -10204 will only appear as a side effect).
  44. // Status code -103 will appear if some assignment submission to the database fails.
  45. //
  46. /** Lets Sloodle know we are in a linker script. */
  47. define('SLOODLE_LINKER_SCRIPT', true);
  48. /** Grab the Sloodle/Moodle configuration. */
  49. require_once('../../init.php');
  50. /** Include the Sloodle PHP API. */
  51. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  52. // Authenticate the request, load the Sloodle Object assignment module, and validate the user
  53. $sloodle = new SloodleSession();
  54. $sloodle->authenticate_request();
  55. $sloodle->load_module('sloodleobject', true);
  56. // Has user data been omitted?
  57. $uuid = $sloodle->request->get_avatar_uuid(false);
  58. $avname = $sloodle->request->get_avatar_name(false);
  59. if ($uuid == null && $avname == null) {
  60. // Just query the assignment details
  61. $sloodle->response->set_status_code(1);
  62. $sloodle->response->set_status_descriptor('OK');
  63. $sloodle->response->add_data_line($sloodle->module->get_name());
  64. $sloodle->response->add_data_line(strip_tags($sloodle->module->get_intro()));
  65. $sloodle->response->render_to_output();
  66. exit();
  67. }
  68. // Some user data has been provided, so make sure we can validate the user
  69. $sloodle->validate_user();
  70. // Check the requirements for allowing submissions
  71. $status = 1; // This means it's OK
  72. if (!$sloodle->module->user_can_submit($sloodle->user)) $status = -10201;
  73. else if ($sloodle->module->user_has_submitted($sloodle->user) == true && $sloodle->module->resubmit_allowed() == false) $status = -10205;
  74. else if ($sloodle->module->is_too_early()) $status = -10202;
  75. else {
  76. $late = $sloodle->module->is_too_late();
  77. if ($late > 0) $status = -10203;
  78. else if ($late < 0) $sloodle->response->add_side_effect(-10204); // Still OK... just late! :-)
  79. }
  80. // If the status was bad, then report it
  81. if ($status < 1) {
  82. $sloodle->response->set_status_code($status);
  83. $sloodle->response->set_status_descriptor('ASSIGNMENT');
  84. $sloodle->response->render_to_output();
  85. exit();
  86. }
  87. // Has an object name been provided?
  88. $sloodleobjname = $sloodle->request->optional_param('sloodleobjname', null);
  89. if ($sloodleobjname == null || empty($sloodleobjname)) {
  90. // No - just checking if the user can submit
  91. $sloodle->response->set_status_code(1);
  92. $sloodle->response->set_status_descriptor('OK');
  93. $sloodle->response->add_data_line('Checked assignment status');
  94. $sloodle->response->render_to_output();
  95. exit();
  96. }
  97. // Object being submitted - fetch our other data
  98. $sloodleprimcount = (int)$sloodle->request->required_param('sloodleprimcount');
  99. $sloodleprimdropname = $sloodle->request->required_param('sloodleprimdropname');
  100. $sloodleprimdropuuid = $sloodle->request->required_param('sloodleprimdropuuid');
  101. $sloodleregion = $sloodle->request->required_param('sloodleregion');
  102. $sloodlepos = $sloodle->request->required_param('sloodlepos');
  103. // Make sure the position is valid
  104. $arr = sloodle_vector_to_array($sloodlepos);
  105. if (!$arr) $sloodlepos = '<0,0,0>';
  106. else $sloodlepos = sloodle_round_vector($sloodlepos);
  107. // Submit all the data
  108. if ($sloodle->module->submit($sloodle->user, $sloodleobjname, $sloodleprimcount, $sloodleprimdropname, $sloodleprimdropuuid, $sloodleregion, $sloodlepos)) {
  109. // OK
  110. $sloodle->response->set_status_code(1);
  111. $sloodle->response->set_status_descriptor('OK');
  112. $sloodle->response->add_data_line('SUBMITTED OBJECT');
  113. } else {
  114. // Error
  115. $sloodle->response->set_status_code(-103);
  116. $sloodle->response->set_status_descriptor('SYSTEM');
  117. $sloodle->response->add_data_line('Failed to add assignment data into database.');
  118. }
  119. // Render the response
  120. $sloodle->response->render_to_output();
  121. exit();
  122. ?>