survey_invitation.php 5.6 KB

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