shibboleth_status_request_form.class.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Shibboleth;
  3. use Display;
  4. /**
  5. * Status request form. Display a form allowing the user to request additional
  6. * rights/ another status.
  7. *
  8. * @license see /license.txt
  9. * @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
  10. */
  11. class ShibbolethStatusRequestForm
  12. {
  13. /**
  14. *
  15. * @return ShibbolethStatusRequestForm
  16. */
  17. public static function instance()
  18. {
  19. static $result = false;
  20. if (empty($result))
  21. {
  22. $result = new self();
  23. }
  24. return $result;
  25. }
  26. function display()
  27. {
  28. if ($this->is_submitted() && $this->get_reason() == '')
  29. {
  30. $reason_is_mandatory = get_lang('ReasonIsMandatory');
  31. echo Display::return_message($reason_is_mandatory, 'error');
  32. }
  33. $status_request_message = get_lang('StatusRequestMessage');
  34. $label_new_status = get_lang('NewStatus');
  35. $label_reason = get_lang('Reason');
  36. $label_ok = get_lang('Ok');
  37. $label_cancel = get_lang('Cancel');
  38. $user = Shibboleth::session()->user();
  39. $items = array();
  40. if ($user['status'] == Shibboleth::UNKNOWN_STATUS)
  41. {
  42. $items[Shibboleth::STUDENT_STATUS] = get_lang('Student');
  43. }
  44. $items[Shibboleth::TEACHER_STATUS] = get_lang('Teacher');
  45. $status_options = '';
  46. foreach ($items as $key => $value)
  47. {
  48. $status_options.= "<option value=\"$key\">$value</option>";
  49. }
  50. return <<<EOT
  51. <div id="askAccountText">
  52. <p>$status_request_message</p>
  53. </div>
  54. <form method="post" action="request.php" id="status_request_form">
  55. <input type="hidden" name="formPosted" value="true"/>
  56. <label for="status">$label_new_status:</label>
  57. <select name="status">
  58. $status_options
  59. </select>
  60. <label for="reason">$label_reason:</label>
  61. <textarea name="reason" style="min-width:400px; min-height:100px;"></textarea>
  62. <p><input name="submit" type="submit" value="$label_ok" style="margin-right:10px;"/><input name="cancel" type="submit" value="$label_cancel" /></p>
  63. </form>
  64. EOT;
  65. }
  66. public function is_submitted()
  67. {
  68. return isset($_POST['submit']) ? $_POST['submit'] : false;
  69. }
  70. public function cancelled()
  71. {
  72. return isset($_POST['cancel']) ? $_POST['cancel'] : false;
  73. }
  74. function get_reason()
  75. {
  76. return isset($_POST['reason']) ? $_POST['reason'] : '';
  77. }
  78. function get_status()
  79. {
  80. return isset($_POST['status']) ? $_POST['status'] : '';
  81. }
  82. }