survey_invitation.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. $tool_name = get_lang('Survey invitations');
  18. $courseInfo = api_get_course_info();
  19. // Getting the survey information
  20. $survey_id = Security::remove_XSS($_GET['survey_id']);
  21. $survey_data = SurveyManager::get_survey($survey_id);
  22. if (empty($survey_data)) {
  23. api_not_allowed(true);
  24. }
  25. $view = isset($_GET['view']) ? $_GET['view'] : 'invited';
  26. $urlname = strip_tags(
  27. api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)
  28. );
  29. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  30. $urlname .= '...';
  31. }
  32. // Breadcrumbs
  33. $interbreadcrumb[] = [
  34. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
  35. 'name' => get_lang('Survey list'),
  36. ];
  37. $interbreadcrumb[] = [
  38. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id,
  39. 'name' => $urlname,
  40. ];
  41. // Displaying the header
  42. Display::display_header($tool_name);
  43. $course_id = api_get_course_int_id();
  44. $sessionId = api_get_session_id();
  45. $sentInvitations = SurveyUtil::getSentInvitations($survey_data['code'], $course_id, $sessionId);
  46. // Getting all the people who have filled this survey
  47. $answered_data = SurveyManager::get_people_who_filled_survey($survey_id);
  48. $invitationsCount = count($sentInvitations);
  49. $answeredCount = count($answered_data);
  50. $unasnweredCount = count($sentInvitations) - count($answered_data);
  51. if ($survey_data['anonymous'] == 1 && !api_get_configuration_value('survey_anonymous_show_answered')) {
  52. echo Display::return_message(
  53. get_lang('This survey is anonymous. You can\'t see who answered.').' '.$answeredCount.' '.get_lang('people answered')
  54. );
  55. $answered_data = [];
  56. }
  57. if ($survey_data['anonymous'] == 1) {
  58. if ($answeredCount < 2) {
  59. $answeredCount = 0;
  60. $unasnweredCount = $invitationsCount;
  61. }
  62. }
  63. $url = api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidreq();
  64. echo '<ul class="nav nav-tabs">';
  65. if ($view == 'invited') {
  66. echo '<li role="presentation" class="active"><a href="#">'.get_lang('View invited');
  67. } else {
  68. echo '<li role="presentation"><a href="'.$url.'&view=invited">'.
  69. get_lang('View invited');
  70. }
  71. echo ' <span class="badge badge-default">'.$invitationsCount.'</span>';
  72. echo '</a></li>';
  73. if ($view == 'answered') {
  74. echo '<li role="presentation" class="active"><a href="#">'.get_lang('View people who answered');
  75. } else {
  76. echo '<li role="presentation"><a href="'.$url.'&view=answered">'.
  77. get_lang('View people who answered');
  78. }
  79. echo ' <span class="badge badge-default">'.$answeredCount.'</span>';
  80. echo '</a></li>';
  81. if ($view == 'unanswered') {
  82. echo '<li role="presentation" class="active"><a href="#">'.get_lang('View people who didn\'t answer');
  83. } else {
  84. echo '<li role="presentation"><a href="'.$url.'&view=unanswered">'.
  85. get_lang('View people who didn\'t answer');
  86. }
  87. echo ' <span class="badge badge-default">'.$unasnweredCount.'</span>';
  88. echo '</a></li>';
  89. echo '</ul>';
  90. // Table header
  91. echo '<table class="data_table" style="margin-top: 5px;">';
  92. echo ' <tr>';
  93. echo ' <th>'.get_lang('User').'</th>';
  94. echo ' <th>'.get_lang('Invitation date').'</th>';
  95. switch ($view) {
  96. case 'unanswered':
  97. echo ' <th>'.get_lang('Survey invitation link').'</th>';
  98. break;
  99. default:
  100. echo ' <th>'.get_lang('Answered').'</th>';
  101. break;
  102. }
  103. echo ' </tr>';
  104. $surveyAnonymousShowAnswered = api_get_configuration_value('survey_anonymous_show_answered');
  105. $hideSurveyReportingButton = api_get_configuration_value('hide_survey_reporting_button');
  106. foreach ($sentInvitations as $row) {
  107. $id = $row['iid'];
  108. if ($view == 'invited' ||
  109. ($view == 'answered' && in_array($row['user'], $answered_data) && $answeredCount > 1) ||
  110. ($view == 'unanswered' && !in_array($row['user'], $answered_data) && $answeredCount > 1)
  111. ) {
  112. echo '<tr>';
  113. if (is_numeric($row['user'])) {
  114. $userInfo = api_get_user_info($row['user']);
  115. echo '<td>';
  116. echo UserManager::getUserProfileLink($userInfo);
  117. echo '</td>';
  118. } else {
  119. echo '<td>'.$row['user'].'</td>';
  120. }
  121. echo ' <td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
  122. if (in_array($row['user'], $answered_data)) {
  123. if (!$surveyAnonymousShowAnswered && !$hideSurveyReportingButton) {
  124. echo '<td>';
  125. echo '<a href="'.
  126. api_get_path(WEB_CODE_PATH).
  127. 'survey/reporting.php?action=userreport&survey_id='.$survey_id.'&user='.$row['user'].'&'.api_get_cidreq().'">'.
  128. get_lang('View answers').'</a>';
  129. echo '</td>';
  130. } else {
  131. if ($survey_data['anonymous'] == 1 && $answeredCount > 1) {
  132. echo '<td>'.get_lang('Answered').'</td>';
  133. } else {
  134. echo '<td>-</td>';
  135. }
  136. }
  137. } else {
  138. if ($view == 'unanswered') {
  139. echo ' <td>';
  140. $code = $row['invitation_code'];
  141. $link = SurveyUtil::generateFillSurveyLink($code, $courseInfo, $sessionId);
  142. $link = Display::input('text', 'copy_'.$id, $link, ['id' => 'copy_'.$id, 'class' => '']);
  143. $link .= ' '.Display::url(
  144. Display::returnFontAwesomeIcon('copy').get_lang('Copy text'),
  145. 'javascript:void()',
  146. ['onclick' => "copyTextToClipBoard('copy_".$id."')", 'class' => 'btn btn-primary btn-sm']
  147. );
  148. echo $link;
  149. echo ' </td>';
  150. } else {
  151. echo '<td>-</td>';
  152. }
  153. }
  154. echo '</tr>';
  155. } elseif ($view === 'unanswered' && $answeredCount == 0) {
  156. echo '<tr>';
  157. if (is_numeric($row['user'])) {
  158. $userInfo = api_get_user_info($row['user']);
  159. echo '<td>';
  160. echo UserManager::getUserProfileLink($userInfo);
  161. echo '</td>';
  162. } else {
  163. echo '<td>'.$row['user'].'</td>';
  164. }
  165. echo ' <td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
  166. echo ' <td>';
  167. $code = $row['invitation_code'];
  168. $link = SurveyUtil::generateFillSurveyLink($code, $courseInfo, $sessionId);
  169. $link = Display::input('text', 'copy_'.$id, $link, ['id' => 'copy_'.$id, 'class' => '']);
  170. $link .= ' '.Display::url(
  171. Display::returnFontAwesomeIcon('copy').get_lang('Copy text'),
  172. 'javascript:void()',
  173. ['onclick' => "copyTextToClipBoard('copy_".$id."')", 'class' => 'btn btn-primary btn-sm']
  174. );
  175. echo $link;
  176. echo ' </td>';
  177. echo '</tr>';
  178. }
  179. }
  180. // Closing the table
  181. echo '</table>';
  182. Display::display_footer();