survey_invitation.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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();
  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('InvitationCode').'</th>';
  105. echo ' <th>'.get_lang('InvitationDate').'</th>';
  106. echo ' <th>'.get_lang('Answered').'</th>';
  107. echo ' </tr>';
  108. $sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email FROM $table_survey_invitation survey_invitation
  109. LEFT JOIN $table_user user ON survey_invitation.user = user.user_id
  110. WHERE survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."'";
  111. $res = api_sql_query($sql, __FILE__, __LINE__);
  112. while ($row = mysql_fetch_assoc($res))
  113. {
  114. 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)))
  115. {
  116. echo '<tr>';
  117. if (is_numeric($row['user']))
  118. {
  119. echo ' <td><a href="../user/userInfo.php?editMainUserInfo='.$row['user'].'">'.$row['firstname'].' '.$row['lastname'].'</a></td>';
  120. }
  121. else
  122. {
  123. echo ' <td>'.$row['user'].'</td>';
  124. }
  125. /** @todo this is temporary to allow the developer to quickly fill a survey as a different user */
  126. // echo ' <td>'.$row['invitation_code'].'</td>';
  127. echo ' <td><a href="fillsurvey.php?course='.$_course['sysCode'].'&amp;invitationcode='.$row['invitation_code'].'">'.$row['invitation_code'].'</td>';
  128. echo ' <td>'.$row['invitation_date'].'</td>';
  129. echo ' <td>';
  130. if (in_array($row['user'], $answered_data))
  131. {
  132. echo '<a href="reporting.php?action=userreport&amp;survey_id='.$_GET['survey_id'].'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
  133. }
  134. else
  135. {
  136. echo '-';
  137. }
  138. echo ' </td>';
  139. echo '</tr>';
  140. }
  141. }
  142. // closing the table
  143. echo '</table>';
  144. // Footer
  145. Display :: display_footer();
  146. /**
  147. * @todo add the additional parameters
  148. */
  149. /*
  150. $table = new SortableTable('survey_invitations', 'get_number_of_survey_invitations', 'get_survey_invitations_data',2);
  151. $table->set_additional_parameters($parameters);
  152. $table->set_header(0, get_lang('User'));
  153. $table->set_header(1, get_lang('InvitationCode'));
  154. $table->set_header(2, get_lang('InvitationDate'));
  155. $table->set_header(3, get_lang('Answered'));
  156. $table->set_column_filter(3, 'modify_filter');
  157. $table->display();
  158. */
  159. /**
  160. * Get all the information about the invitations of a certain survey
  161. *
  162. * @return unknown
  163. *
  164. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  165. * @version January 2007
  166. *
  167. * @todo use survey_id parameter instead of $_GET
  168. */
  169. function get_survey_invitations_data()
  170. {
  171. // Database table definition
  172. $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
  173. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  174. $sql = "SELECT
  175. survey_invitation.user as col1,
  176. survey_invitation.invitation_code as col2,
  177. survey_invitation.invitation_date as col3,
  178. '' as col4
  179. FROM $table_survey_invitation survey_invitation
  180. LEFT JOIN $table_user user ON survey_invitation.user = user.user_id
  181. WHERE survey_invitation.survey_id = '".Database::escape_string($_GET['survey_id'])."'";
  182. $res = api_sql_query($sql, __FILE__, __LINE__);
  183. while ($row = mysql_fetch_array($res))
  184. {
  185. $survey_invitation_data[] = $row;
  186. }
  187. return $survey_invitation_data;
  188. }
  189. /**
  190. * Get the total number of survey invitations for a given survey (through $_GET['survey_id'])
  191. *
  192. * @return unknown
  193. *
  194. * @todo use survey_id parameter instead of $_GET
  195. *
  196. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  197. * @version January 2007
  198. */
  199. function get_number_of_survey_invitations()
  200. {
  201. // Database table definition
  202. $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
  203. $sql = "SELECT count(user) AS total FROM $table_survey_invitation WHERE survey_id='".Database::escape_string($_GET['survey_id'])."'";
  204. $res = api_sql_query($sql, __FILE__, __LINE__);
  205. $row = mysql_fetch_assoc($res);
  206. return $row['total'];
  207. }
  208. /**
  209. * @todo use global array for answered or not
  210. *
  211. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  212. * @version January 2007
  213. */
  214. function modify_filter()
  215. {
  216. }
  217. ?>