survey_invitation.php 5.1 KB

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