survey_invitation.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.survey
  5. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  6. * @version $Id: survey_invite.php 10680 2007-01-11 21:26:23Z pcool $
  7. *
  8. * @todo the answered column
  9. */
  10. // Including the global initialization file
  11. require '../inc/global.inc.php';
  12. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  13. if (!api_is_allowed_to_edit(false, true)) {
  14. Display :: display_header(get_lang('ToolSurvey'));
  15. Display :: display_error_message(get_lang('NotAllowed'), false);
  16. Display :: display_footer();
  17. exit;
  18. }
  19. // Database table definitions
  20. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  21. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  22. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  23. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  24. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  25. $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
  26. $tool_name = get_lang('SurveyInvitations');
  27. // Getting the survey information
  28. // We exit here if ther is no valid $_GET parameter
  29. if (!isset($_GET['survey_id']) OR !is_numeric($_GET['survey_id'])) {
  30. Display :: display_header($tool_name);
  31. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  32. Display :: display_footer();
  33. exit;
  34. }
  35. $survey_id = Security::remove_XSS($_GET['survey_id']);
  36. $survey_data = SurveyManager::get_survey($survey_id);
  37. if (empty($survey_data)) {
  38. Display :: display_header($tool_name);
  39. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  40. Display :: display_footer();
  41. exit;
  42. }
  43. $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
  44. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  45. $urlname .= '...';
  46. }
  47. // Breadcrumbs
  48. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
  49. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
  50. // Displaying the header
  51. Display::display_header($tool_name);
  52. // Checking the parameters
  53. if (!is_numeric($survey_id)) {
  54. Display::display_error_message(get_lang('Error'), false);
  55. Display::display_footer();
  56. exit;
  57. }
  58. // Getting all the people who have filled this survey
  59. $answered_data = SurveyManager::get_people_who_filled_survey($survey_id);
  60. if ($survey_data['anonymous'] == 1) {
  61. Display::display_normal_message(get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count($answered_data).' '.get_lang('PeopleAnswered'));
  62. $answered_data = array();
  63. }
  64. if (!isset($_GET['view']) OR $_GET['view'] == 'invited') {
  65. echo get_lang('ViewInvited'). ' | ';
  66. } else {
  67. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=invited">'.get_lang('ViewInvited').'</a> |';
  68. }
  69. if ($_GET['view'] == 'answered') {
  70. echo get_lang('ViewAnswered').' | ';
  71. } else {
  72. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=answered">'.get_lang('ViewAnswered').'</a> |';
  73. }
  74. if ($_GET['view'] == 'unanswered') {
  75. echo get_lang('ViewUnanswered');
  76. } else {
  77. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=unanswered">'.get_lang('ViewUnanswered').'</a>';
  78. }
  79. // Table header
  80. echo '<table class="data_table">';
  81. echo ' <tr>';
  82. echo ' <th>'.get_lang('User').'</th>';
  83. echo ' <th>'.get_lang('InvitationDate').'</th>';
  84. echo ' <th>'.get_lang('Answered').'</th>';
  85. echo ' </tr>';
  86. $course_id = api_get_course_int_id();
  87. $sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email
  88. FROM $table_survey_invitation survey_invitation
  89. LEFT JOIN $table_user user
  90. ON (survey_invitation.user = user.user_id AND survey_invitation.c_id = $course_id)
  91. WHERE
  92. survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."' ";
  93. $res = Database::query($sql);
  94. while ($row = Database::fetch_assoc($res)) {
  95. if (!$_GET['view'] ||
  96. $_GET['view'] == 'invited' ||
  97. ($_GET['view'] == 'answered' && in_array($row['user'], $answered_data)) ||
  98. ($_GET['view'] == 'unanswered' && !in_array($row['user'], $answered_data))
  99. ) {
  100. echo '<tr>';
  101. if (is_numeric($row['user'])) {
  102. $userInfo = api_get_user_info($row['user']);
  103. echo '<td>';
  104. echo UserManager::getUserProfileLink($userInfo);
  105. echo '</td>';
  106. } else {
  107. echo '<td>'.$row['user'].'</td>';
  108. }
  109. echo ' <td>'.$row['invitation_date'].'</td>';
  110. echo ' <td>';
  111. if (in_array($row['user'], $answered_data)) {
  112. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$survey_id.'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
  113. } else {
  114. echo '-';
  115. }
  116. echo ' </td>';
  117. echo '</tr>';
  118. }
  119. }
  120. // Closing the table
  121. echo '</table>';
  122. // Footer
  123. Display :: display_footer();