survey_invitation.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.survey
  18. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  19. * @version $Id: survey_invite.php 10680 2007-01-11 21:26:23Z pcool $
  20. *
  21. * @todo the answered column
  22. */
  23. // name of the language file that needs to be included
  24. $language_file = 'survey';
  25. // including the global dokeos file
  26. require ('../inc/global.inc.php');
  27. // including additional libraries
  28. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  29. require_once('survey.lib.php');
  30. require_once (api_get_path(LIBRARY_PATH)."course.lib.php");
  31. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  32. require_once (api_get_path(LIBRARY_PATH)."mail.lib.inc.php");
  33. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  34. if (!api_is_allowed_to_edit(false,true))
  35. {
  36. Display :: display_header(get_lang('ToolSurvey'));
  37. Display :: display_error_message(get_lang('NotAllowed'), false);
  38. Display :: display_footer();
  39. exit;
  40. }
  41. // Database table definitions
  42. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  43. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  44. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  45. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  46. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  47. $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
  48. $tool_name = get_lang('SurveyInvitations');
  49. // getting the survey information
  50. // We exit here if ther is no valid $_GET parameter
  51. if (!isset($_GET['survey_id']) OR !is_numeric($_GET['survey_id']))
  52. {
  53. Display :: display_header($tool_name);
  54. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  55. Display :: display_footer();
  56. exit;
  57. }
  58. $survey_id = Security::remove_XSS($_GET['survey_id']);
  59. $survey_data = survey_manager::get_survey($survey_id);
  60. if (empty($survey_data)) {
  61. Display :: display_header($tool_name);
  62. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  63. Display :: display_footer();
  64. exit;
  65. }
  66. $urlname =strip_tags(api_substr(api_html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40));
  67. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  68. $urlname .= '...';
  69. }
  70. //breadcrumbs
  71. $interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  72. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
  73. // Displaying the header
  74. Display::display_header($tool_name);
  75. // Checking the parameters
  76. if (!is_numeric($survey_id))
  77. {
  78. Display::display_error_message(get_lang('Error'), false);
  79. Display::display_footer();
  80. exit;
  81. }
  82. // Getting all the people who have filled this survey
  83. $answered_data = survey_manager::get_people_who_filled_survey($survey_id);
  84. if ($survey_data['anonymous'] == 1)
  85. {
  86. Display::display_normal_message(get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count($answered_data).' '.get_lang('PeopleAnswered'));
  87. $answered_data = array();
  88. }
  89. //
  90. if (!isset($_GET['view']) OR $_GET['view'] == 'invited')
  91. {
  92. echo get_lang('ViewInvited'). ' | ';
  93. }
  94. else
  95. {
  96. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=invited">'.get_lang('ViewInvited').'</a> |';
  97. }
  98. if ($_GET['view'] == 'answered')
  99. {
  100. echo get_lang('ViewAnswered').' | ';
  101. }
  102. else
  103. {
  104. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=answered">'.get_lang('ViewAnswered').'</a> |';
  105. }
  106. if ($_GET['view'] == 'unanswered')
  107. {
  108. echo get_lang('ViewUnanswered');
  109. }
  110. else
  111. {
  112. echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=unanswered">'.get_lang('ViewUnanswered').'</a>';
  113. }
  114. // table header
  115. echo '<table class="data_table">';
  116. echo ' <tr>';
  117. echo ' <th>'.get_lang('User').'</th>';
  118. echo ' <th>'.get_lang('InvitationDate').'</th>';
  119. echo ' <th>'.get_lang('Answered').'</th>';
  120. echo ' </tr>';
  121. $sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email FROM $table_survey_invitation survey_invitation
  122. LEFT JOIN $table_user user ON survey_invitation.user = user.user_id
  123. WHERE survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."'";
  124. $res = Database::query($sql);
  125. while ($row = Database::fetch_assoc($res))
  126. {
  127. if (!$_GET['view'] OR $_GET['view'] == 'invited' OR ($_GET['view'] == 'answered' AND in_array($row['user'], $answered_data)) OR ($_GET['view'] == 'unanswered' AND !in_array($row['user'], $answered_data)))
  128. {
  129. echo '<tr>';
  130. if (is_numeric($row['user']))
  131. {
  132. echo ' <td><a href="../user/userInfo.php?editMainUserInfo='.$row['user'].'">'.api_get_person_name($row['firstname'], $row['lastname']).'</a></td>';
  133. }
  134. else
  135. {
  136. echo ' <td>'.$row['user'].'</td>';
  137. }
  138. echo ' <td>'.$row['invitation_date'].'</td>';
  139. echo ' <td>';
  140. if (in_array($row['user'], $answered_data))
  141. {
  142. echo '<a href="reporting.php?action=userreport&amp;survey_id='.$survey_id.'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
  143. }
  144. else
  145. {
  146. echo '-';
  147. }
  148. echo ' </td>';
  149. echo '</tr>';
  150. }
  151. }
  152. // closing the table
  153. echo '</table>';
  154. // Footer
  155. Display :: display_footer();
  156. /**
  157. * @todo add the additional parameters
  158. */
  159. /*
  160. $table = new SortableTable('survey_invitations', 'get_number_of_survey_invitations', 'get_survey_invitations_data',2);
  161. $table->set_additional_parameters($parameters);
  162. $table->set_header(0, get_lang('User'));
  163. $table->set_header(1, get_lang('InvitationCode'));
  164. $table->set_header(2, get_lang('InvitationDate'));
  165. $table->set_header(3, get_lang('Answered'));
  166. $table->set_column_filter(3, 'SurveyUtil::modify_filter');
  167. $table->display();
  168. */