survey_invitation.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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())
  35. {
  36. Display :: display_header(get_lang('Survey'));
  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. // getting the survey information
  49. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  50. $urlname = substr(strip_tags($survey_data['title']), 0, 40);
  51. if (strlen(strip_tags($survey_data['title'])) > 40)
  52. {
  53. $urlname .= '...';
  54. }
  55. // breadcrumbs
  56. $interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  57. $interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
  58. $tool_name = get_lang('SurveyInvitations');
  59. // Displaying the header
  60. Display::display_header($tool_name);
  61. // Checking the parameters
  62. if (!is_numeric($_GET['survey_id']))
  63. {
  64. Display::display_error_message(get_lang('Error'), false);
  65. Display::display_footer();
  66. exit;
  67. }
  68. // Getting all the people who have filled this survey
  69. $answered_data = survey_manager::get_people_who_filled_survey($_GET['survey_id']);
  70. if ($survey_data['anonymous'] == 1)
  71. {
  72. Display::display_normal_message(get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count($answered_data).' '.get_lang('PeopleAnswered'));
  73. $answered_data = array();
  74. }
  75. //
  76. if (!isset($_GET['view']) OR $_GET['view'] == 'invited')
  77. {
  78. echo get_lang('ViewInvited'). ' | ';
  79. }
  80. else
  81. {
  82. echo ' <a href="'.api_get_self().'?survey_id='.(int)$_GET['survey_id'].'&amp;view=invited">'.get_lang('ViewInvited').'</a> |';
  83. }
  84. if ($_GET['view'] == 'answered')
  85. {
  86. echo get_lang('ViewAnswered').' | ';
  87. }
  88. else
  89. {
  90. echo ' <a href="'.api_get_self().'?survey_id='.(int)$_GET['survey_id'].'&amp;view=answered">'.get_lang('ViewAnswered').'</a> |';
  91. }
  92. if ($_GET['view'] == 'unanswered')
  93. {
  94. echo get_lang('ViewUnanswered');
  95. }
  96. else
  97. {
  98. echo ' <a href="'.api_get_self().'?survey_id='.(int)$_GET['survey_id'].'&amp;view=unanswered">'.get_lang('ViewUnanswered').'</a>';
  99. }
  100. // table header
  101. echo '<table class="data_table">';
  102. echo ' <tr>';
  103. echo ' <th>'.get_lang('User').'</th>';
  104. echo ' <th>'.get_lang('InvitationDate').'</th>';
  105. echo ' <th>'.get_lang('Answered').'</th>';
  106. echo ' </tr>';
  107. $sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email FROM $table_survey_invitation survey_invitation
  108. LEFT JOIN $table_user user ON survey_invitation.user = user.user_id
  109. WHERE survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."'";
  110. $res = api_sql_query($sql, __FILE__, __LINE__);
  111. while ($row = mysql_fetch_assoc($res))
  112. {
  113. 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)))
  114. {
  115. echo '<tr>';
  116. if (is_numeric($row['user']))
  117. {
  118. echo ' <td><a href="../user/userInfo.php?editMainUserInfo='.$row['user'].'">'.$row['firstname'].' '.$row['lastname'].'</a></td>';
  119. }
  120. else
  121. {
  122. echo ' <td>'.$row['user'].'</td>';
  123. }
  124. echo ' <td>'.$row['invitation_date'].'</td>';
  125. echo ' <td>';
  126. if (in_array($row['user'], $answered_data))
  127. {
  128. echo '<a href="reporting.php?action=userreport&amp;survey_id='.$_GET['survey_id'].'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
  129. }
  130. else
  131. {
  132. echo '-';
  133. }
  134. echo ' </td>';
  135. echo '</tr>';
  136. }
  137. }
  138. // closing the table
  139. echo '</table>';
  140. // Footer
  141. Display :: display_footer();
  142. /**
  143. * @todo add the additional parameters
  144. */
  145. /*
  146. $table = new SortableTable('survey_invitations', 'get_number_of_survey_invitations', 'get_survey_invitations_data',2);
  147. $table->set_additional_parameters($parameters);
  148. $table->set_header(0, get_lang('User'));
  149. $table->set_header(1, get_lang('InvitationCode'));
  150. $table->set_header(2, get_lang('InvitationDate'));
  151. $table->set_header(3, get_lang('Answered'));
  152. $table->set_column_filter(3, 'SurveyUtil::modify_filter');
  153. $table->display();
  154. */