survey_invitation.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.survey
  5. *
  6. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  7. *
  8. * @version $Id: survey_invite.php 10680 2007-01-11 21:26:23Z pcool $
  9. *
  10. * @todo the answered column
  11. */
  12. require_once __DIR__.'/../inc/global.inc.php';
  13. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  14. if (!api_is_allowed_to_edit(false, true)) {
  15. api_not_allowed(true);
  16. }
  17. // Database table definitions
  18. $table_survey = Database::get_course_table(TABLE_SURVEY);
  19. $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
  20. $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  21. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  22. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  23. $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
  24. $tool_name = get_lang('SurveyInvitations');
  25. $courseInfo = api_get_course_info();
  26. // Getting the survey information
  27. $survey_id = Security::remove_XSS($_GET['survey_id']);
  28. $survey_data = SurveyManager::get_survey($survey_id);
  29. if (empty($survey_data)) {
  30. api_not_allowed(true);
  31. }
  32. $view = isset($_GET['view']) ? $_GET['view'] : 'invited';
  33. $urlname = strip_tags(
  34. api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)
  35. );
  36. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  37. $urlname .= '...';
  38. }
  39. // Breadcrumbs
  40. $interbreadcrumb[] = [
  41. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
  42. 'name' => get_lang('SurveyList'),
  43. ];
  44. $interbreadcrumb[] = [
  45. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id,
  46. 'name' => $urlname,
  47. ];
  48. // Displaying the header
  49. Display::display_header($tool_name);
  50. $course_id = api_get_course_int_id();
  51. $sessionId = api_get_session_id();
  52. $sentInvitations = SurveyUtil::getSentInvitations($survey_data['code'], $course_id, $sessionId);
  53. // Getting all the people who have filled this survey
  54. $answered_data = SurveyManager::get_people_who_filled_survey($survey_id);
  55. $invitationsCount = count($sentInvitations);
  56. $answeredCount = count($answered_data);
  57. $unasnweredCount = count($sentInvitations) - count($answered_data);
  58. if ($survey_data['anonymous'] == 1 && !api_get_configuration_value('survey_anonymous_show_answered')) {
  59. echo Display::return_message(
  60. get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.$answeredCount.' '.get_lang('PeopleAnswered')
  61. );
  62. $answered_data = [];
  63. }
  64. if ($survey_data['anonymous'] == 1) {
  65. if ($answeredCount < 2) {
  66. $answeredCount = 0;
  67. $unasnweredCount = $invitationsCount;
  68. }
  69. }
  70. $url = api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidreq();
  71. echo '<ul class="nav nav-tabs">';
  72. if ($view == 'invited') {
  73. echo '<li role="presentation" class="active"><a href="#">'.get_lang('ViewInvited');
  74. } else {
  75. echo '<li role="presentation"><a href="'.$url.'&view=invited">'.
  76. get_lang('ViewInvited');
  77. }
  78. echo ' <span class="badge badge-default">'.$invitationsCount.'</span>';
  79. echo '</a></li>';
  80. if ($view == 'answered') {
  81. echo '<li role="presentation" class="active"><a href="#">'.get_lang('ViewAnswered');
  82. } else {
  83. echo '<li role="presentation"><a href="'.$url.'&view=answered">'.
  84. get_lang('ViewAnswered');
  85. }
  86. echo ' <span class="badge badge-default">'.$answeredCount.'</span>';
  87. echo '</a></li>';
  88. if ($view == 'unanswered') {
  89. echo '<li role="presentation" class="active"><a href="#">'.get_lang('ViewUnanswered');
  90. } else {
  91. echo '<li role="presentation"><a href="'.$url.'&view=unanswered">'.
  92. get_lang('ViewUnanswered');
  93. }
  94. echo ' <span class="badge badge-default">'.$unasnweredCount.'</span>';
  95. echo '</a></li>';
  96. echo '</ul>';
  97. // Table header
  98. echo '<table class="data_table" style="margin-top: 5px;">';
  99. echo ' <tr>';
  100. echo ' <th>'.get_lang('User').'</th>';
  101. echo ' <th>'.get_lang('InvitationDate').'</th>';
  102. switch ($view) {
  103. case 'unanswered':
  104. echo ' <th>'.get_lang('SurveyInviteLink').'</th>';
  105. break;
  106. default:
  107. echo ' <th>'.get_lang('Answered').'</th>';
  108. break;
  109. }
  110. echo ' </tr>';
  111. $surveyAnonymousShowAnswered = api_get_configuration_value('survey_anonymous_show_answered');
  112. $hideSurveyReportingButton = api_get_configuration_value('hide_survey_reporting_button');
  113. foreach ($sentInvitations as $row) {
  114. $id = $row['iid'];
  115. if ($view == 'invited' ||
  116. ($view == 'answered' && in_array($row['user'], $answered_data) && $answeredCount > 1) ||
  117. ($view == 'unanswered' && !in_array($row['user'], $answered_data) && $answeredCount > 1)
  118. ) {
  119. echo '<tr>';
  120. if (is_numeric($row['user'])) {
  121. $userInfo = api_get_user_info($row['user']);
  122. echo '<td>';
  123. echo UserManager::getUserProfileLink($userInfo);
  124. echo '</td>';
  125. } else {
  126. echo '<td>'.$row['user'].'</td>';
  127. }
  128. echo ' <td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
  129. if (in_array($row['user'], $answered_data)) {
  130. if (!$surveyAnonymousShowAnswered && !$hideSurveyReportingButton) {
  131. echo '<td>';
  132. echo '<a href="'.
  133. api_get_path(WEB_CODE_PATH).
  134. 'survey/reporting.php?action=userreport&survey_id='.$survey_id.'&user='.$row['user'].'&'.api_get_cidreq().'">'.
  135. get_lang('ViewAnswers').'</a>';
  136. echo '</td>';
  137. } else {
  138. if ($survey_data['anonymous'] == 1 && $answeredCount > 1) {
  139. echo '<td>'.get_lang('Answered').'</td>';
  140. } else {
  141. echo '<td>-</td>';
  142. }
  143. }
  144. } else {
  145. if ($view == 'unanswered') {
  146. echo ' <td>';
  147. $code = $row['invitation_code'];
  148. $link = SurveyUtil::generateFillSurveyLink($code, $courseInfo, $sessionId);
  149. $link = Display::input('text', 'copy_'.$id, $link, ['id' => 'copy_'.$id, 'class' => '']);
  150. $link .= ' '.Display::url(
  151. Display::returnFontAwesomeIcon('copy').get_lang('CopyTextToClipboard'),
  152. 'javascript:void()',
  153. ['onclick' => "copyTextToClipBoard('copy_".$id."')", 'class' => 'btn btn-primary btn-sm']
  154. );
  155. echo $link;
  156. echo ' </td>';
  157. } else {
  158. echo '<td>-</td>';
  159. }
  160. }
  161. echo '</tr>';
  162. } elseif ($view === 'unanswered' && $answeredCount == 0) {
  163. echo '<tr>';
  164. if (is_numeric($row['user'])) {
  165. $userInfo = api_get_user_info($row['user']);
  166. echo '<td>';
  167. echo UserManager::getUserProfileLink($userInfo);
  168. echo '</td>';
  169. } else {
  170. echo '<td>'.$row['user'].'</td>';
  171. }
  172. echo ' <td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
  173. echo ' <td>';
  174. $code = $row['invitation_code'];
  175. $link = SurveyUtil::generateFillSurveyLink($code, $courseInfo, $sessionId);
  176. $link = Display::input('text', 'copy_'.$id, $link, ['id' => 'copy_'.$id, 'class' => '']);
  177. $link .= ' '.Display::url(
  178. Display::returnFontAwesomeIcon('copy').get_lang('CopyTextToClipboard'),
  179. 'javascript:void()',
  180. ['onclick' => "copyTextToClipBoard('copy_".$id."')", 'class' => 'btn btn-primary btn-sm']
  181. );
  182. echo $link;
  183. echo ' </td>';
  184. echo '</tr>';
  185. }
  186. }
  187. // Closing the table
  188. echo '</table>';
  189. Display::display_footer();