survey_invitation.php 7.8 KB

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