survey_invitation.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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(
  49. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
  50. 'name' => get_lang('SurveyList')
  51. );
  52. $interbreadcrumb[] = array(
  53. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
  54. 'name' => $urlname
  55. );
  56. // Displaying the header
  57. Display::display_header($tool_name);
  58. // Checking the parameters
  59. if (!is_numeric($survey_id)) {
  60. api_not_allowed(true, get_lang('Error'));
  61. }
  62. // Getting all the people who have filled this survey
  63. $answered_data = SurveyManager::get_people_who_filled_survey($survey_id);
  64. if ($survey_data['anonymous'] == 1) {
  65. Display::display_normal_message(
  66. get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count($answered_data).' '.get_lang('PeopleAnswered')
  67. );
  68. $answered_data = array();
  69. }
  70. if (!isset($_GET['view']) OR $_GET['view'] == 'invited') {
  71. echo get_lang('ViewInvited'). ' | ';
  72. } else {
  73. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=invited">'.get_lang('ViewInvited').'</a> |';
  74. }
  75. if ($_GET['view'] == 'answered') {
  76. echo get_lang('ViewAnswered').' | ';
  77. } else {
  78. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=answered">'.get_lang('ViewAnswered').'</a> |';
  79. }
  80. if ($_GET['view'] == 'unanswered') {
  81. echo get_lang('ViewUnanswered');
  82. } else {
  83. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=unanswered">'.get_lang('ViewUnanswered').'</a>';
  84. }
  85. // Table header
  86. echo '<table class="data_table">';
  87. echo ' <tr>';
  88. echo ' <th>'.get_lang('User').'</th>';
  89. echo ' <th>'.get_lang('InvitationDate').'</th>';
  90. echo ' <th>'.get_lang('Answered').'</th>';
  91. echo ' </tr>';
  92. $course_id = api_get_course_int_id();
  93. $sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email
  94. FROM $table_survey_invitation survey_invitation
  95. LEFT JOIN $table_user user
  96. ON (survey_invitation.user = user.user_id AND survey_invitation.c_id = $course_id)
  97. WHERE
  98. survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."' ";
  99. $res = Database::query($sql);
  100. while ($row = Database::fetch_assoc($res)) {
  101. if (!$_GET['view'] ||
  102. $_GET['view'] == 'invited' ||
  103. ($_GET['view'] == 'answered' && in_array($row['user'], $answered_data)) ||
  104. ($_GET['view'] == 'unanswered' && !in_array($row['user'], $answered_data))
  105. ) {
  106. echo '<tr>';
  107. if (is_numeric($row['user'])) {
  108. $userInfo = api_get_user_info($row['user']);
  109. echo '<td>';
  110. echo UserManager::getUserProfileLink($userInfo);
  111. echo '</td>';
  112. } else {
  113. echo '<td>'.$row['user'].'</td>';
  114. }
  115. echo ' <td>'.$row['invitation_date'].'</td>';
  116. echo ' <td>';
  117. if (in_array($row['user'], $answered_data)) {
  118. 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>';
  119. } else {
  120. echo '-';
  121. }
  122. echo ' </td>';
  123. echo '</tr>';
  124. }
  125. }
  126. // Closing the table
  127. echo '</table>';