survey_invitation.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. require_once __DIR__.'/../inc/global.inc.php';
  11. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  12. if (!api_is_allowed_to_edit(false, true)) {
  13. api_not_allowed(true);
  14. }
  15. // Database table definitions
  16. $table_survey = Database::get_course_table(TABLE_SURVEY);
  17. $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
  18. $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  19. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  20. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  21. $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
  22. $tool_name = get_lang('SurveyInvitations');
  23. // Getting the survey information
  24. $survey_id = Security::remove_XSS($_GET['survey_id']);
  25. $survey_data = SurveyManager::get_survey($survey_id);
  26. if (empty($survey_data)) {
  27. api_not_allowed(true);
  28. }
  29. $urlname = strip_tags(
  30. api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)
  31. );
  32. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  33. $urlname .= '...';
  34. }
  35. // Breadcrumbs
  36. $interbreadcrumb[] = array(
  37. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
  38. 'name' => get_lang('SurveyList')
  39. );
  40. $interbreadcrumb[] = array(
  41. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id,
  42. 'name' => $urlname
  43. );
  44. // Displaying the header
  45. Display::display_header($tool_name);
  46. // Getting all the people who have filled this survey
  47. $answered_data = SurveyManager::get_people_who_filled_survey($survey_id);
  48. if ($survey_data['anonymous'] == 1) {
  49. echo Display::return_message(
  50. get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count(
  51. $answered_data
  52. ).' '.get_lang('PeopleAnswered')
  53. );
  54. $answered_data = array();
  55. }
  56. if (!isset($_GET['view']) || $_GET['view'] == 'invited') {
  57. echo get_lang('ViewInvited').' | ';
  58. } else {
  59. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=invited">'.get_lang('ViewInvited').'</a> |';
  60. }
  61. if ($_GET['view'] == 'answered') {
  62. echo get_lang('ViewAnswered').' | ';
  63. } else {
  64. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=answered">'.get_lang('ViewAnswered').'</a> |';
  65. }
  66. if ($_GET['view'] == 'unanswered') {
  67. echo get_lang('ViewUnanswered');
  68. } else {
  69. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=unanswered">'.get_lang('ViewUnanswered').'</a>';
  70. }
  71. // Table header
  72. echo '<table class="data_table">';
  73. echo ' <tr>';
  74. echo ' <th>'.get_lang('User').'</th>';
  75. echo ' <th>'.get_lang('InvitationDate').'</th>';
  76. echo ' <th>'.get_lang('Answered').'</th>';
  77. echo ' </tr>';
  78. $course_id = api_get_course_int_id();
  79. $sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email
  80. FROM $table_survey_invitation survey_invitation
  81. LEFT JOIN $table_user user
  82. ON (survey_invitation.user = user.id AND survey_invitation.c_id = $course_id)
  83. WHERE
  84. survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."' ";
  85. $res = Database::query($sql);
  86. while ($row = Database::fetch_assoc($res)) {
  87. if (!$_GET['view'] || $_GET['view'] == 'invited' ||
  88. ($_GET['view'] == 'answered' && in_array($row['user'], $answered_data)) ||
  89. ($_GET['view'] == 'unanswered' && !in_array($row['user'], $answered_data))
  90. ) {
  91. echo '<tr>';
  92. if (is_numeric($row['user'])) {
  93. $userInfo = api_get_user_info($row['user']);
  94. echo '<td>';
  95. echo UserManager::getUserProfileLink($userInfo);
  96. echo '</td>';
  97. } else {
  98. echo '<td>'.$row['user'].'</td>';
  99. }
  100. echo ' <td>'.$row['invitation_date'].'</td>';
  101. echo ' <td>';
  102. if (in_array($row['user'], $answered_data) && !api_get_configuration_value('hide_survey_reporting_button')) {
  103. 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>';
  104. } else {
  105. echo '-';
  106. }
  107. echo ' </td>';
  108. echo '</tr>';
  109. }
  110. }
  111. // Closing the table
  112. echo '</table>';
  113. // Footer
  114. Display::display_footer();