meeting.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. api_protect_course_script(true);
  5. $sessionId = api_get_session_id();
  6. $courseId = api_get_course_int_id();
  7. $userId = api_get_user_id();
  8. $courseInfo = api_get_course_info();
  9. $surveyId = isset($_REQUEST['survey_id']) ? (int) $_REQUEST['survey_id'] : 0;
  10. $invitationcode = isset($_REQUEST['invitationcode']) ? Database::escape_string($_REQUEST['invitationcode']) : 0;
  11. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  12. if (!empty($invitationcode) || !api_is_allowed_to_edit()) {
  13. $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
  14. $table_survey = Database::get_course_table(TABLE_SURVEY);
  15. $sql = "SELECT * FROM $table_survey_invitation
  16. WHERE
  17. c_id = $courseId AND
  18. invitation_code = '".Database::escape_string($invitationcode)."'";
  19. $result = Database::query($sql);
  20. if (Database::num_rows($result) < 1) {
  21. api_not_allowed(true, get_lang('Wrong invitation code'));
  22. }
  23. $survey_invitation = Database::fetch_array($result, 'ASSOC');
  24. $sql = "SELECT * FROM $table_survey
  25. WHERE
  26. c_id = $courseId AND
  27. code = '".Database::escape_string($survey_invitation['survey_code'])."'";
  28. $sql .= api_get_session_condition($sessionId);
  29. $result = Database::query($sql);
  30. $result = Database::fetch_array($result, 'ASSOC');
  31. $surveyId = $result['iid'];
  32. }
  33. $surveyData = SurveyManager::get_survey($surveyId);
  34. if (empty($surveyData)) {
  35. api_not_allowed(true);
  36. }
  37. SurveyManager::checkTimeAvailability($surveyData);
  38. $invitations = SurveyUtil::get_invited_users($surveyData['code']);
  39. $students = isset($invitations['course_users']) ? $invitations['course_users'] : [];
  40. $content = Display::page_header($surveyData['title']);
  41. $interbreadcrumb[] = [
  42. 'url' => api_get_path(WEB_CODE_PATH).
  43. 'survey/survey_list.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId,
  44. 'name' => get_lang('Survey list'),
  45. ];
  46. $questions = SurveyManager::get_questions($surveyData['iid']);
  47. $url = api_get_self().'?survey_id='.$surveyId.'&invitationcode='.$invitationcode.'&'.api_get_cidreq();
  48. $urlEdit = $url.'&action=edit';
  49. if (isset($_POST) && !empty($_POST)) {
  50. $options = isset($_POST['options']) ? array_keys($_POST['options']) : [];
  51. foreach ($questions as $item) {
  52. $questionId = $item['question_id'];
  53. SurveyUtil::remove_answer(
  54. $userId,
  55. $surveyId,
  56. $questionId,
  57. $courseId
  58. );
  59. }
  60. $status = 1;
  61. if (!empty($options)) {
  62. foreach ($options as $selectedQuestionId) {
  63. SurveyUtil::store_answer(
  64. $userId,
  65. $surveyId,
  66. $selectedQuestionId,
  67. 1,
  68. $status,
  69. $surveyData
  70. );
  71. }
  72. } else {
  73. foreach ($questions as $item) {
  74. $questionId = $item['question_id'];
  75. SurveyUtil::store_answer(
  76. $userId,
  77. $surveyId,
  78. $questionId,
  79. 1,
  80. 0,
  81. $surveyData
  82. );
  83. }
  84. }
  85. SurveyManager::update_survey_answered(
  86. $surveyData,
  87. $survey_invitation['user'],
  88. $survey_invitation['survey_code']
  89. );
  90. Display::addFlash(Display::return_message(get_lang('Saved.')));
  91. header('Location: '.$url);
  92. exit;
  93. }
  94. $template = new Template();
  95. $table = new HTML_Table(['class' => 'table']);
  96. $row = 0;
  97. $column = 1;
  98. $answerList = [];
  99. foreach ($questions as $item) {
  100. $answers = SurveyUtil::get_answers_of_question_by_user($surveyId, $item['question_id']);
  101. foreach ($answers as $tempUserId => &$value) {
  102. $value = $value[0];
  103. $value = explode('*', $value);
  104. $value = isset($value[1]) ? $value[1] : 0;
  105. }
  106. $answerList[$item['question_id']] = $answers;
  107. $parts = explode('@@', $item['question']);
  108. $startDateTime = api_get_local_time($parts[0]);
  109. $endDateTime = api_get_local_time($parts[1]);
  110. $date = explode(' ', $startDateTime);
  111. $endDate = explode(' ', $endDateTime);
  112. $mainDate = $date[0];
  113. $startTime = isset($date[1]) && !empty($date[1]) ? sprintf(get_lang('From %s'), $date[1]) : '';
  114. $endTime = isset($endDate[1]) && !empty($endDate[1]) ? sprintf(get_lang('To %s'), $endDate[1]) : '';
  115. if (isset($date[1]) && isset($endDate[1])) {
  116. if ($date[1] === $endDate[1]) {
  117. $startTime = '';
  118. $endTime = '';
  119. }
  120. }
  121. $mainDate = api_format_date($mainDate, DATE_FORMAT_SHORT);
  122. $table->setHeaderContents($row, $column, "<h4>$mainDate</h4> $startTime <br >$endTime");
  123. $column++;
  124. }
  125. $row = 1;
  126. $column = 0;
  127. // Total counter
  128. $table->setHeaderContents(
  129. $row,
  130. 0,
  131. get_lang('Number of users').': '.count($students)
  132. );
  133. foreach ($questions as $item) {
  134. $questionId = $item['question_id'];
  135. $count = 0;
  136. $questionsWithAnswer = 0;
  137. if (isset($answerList[$questionId])) {
  138. foreach ($answerList[$questionId] as $userAnswer) {
  139. if ((int) $userAnswer === 1) {
  140. $questionsWithAnswer++;
  141. }
  142. }
  143. $count = '<p style="color:cornflowerblue" >
  144. <span class="fa fa-check fa-2x"></span>'.$questionsWithAnswer.'</p>';
  145. }
  146. $table->setHeaderContents(
  147. $row,
  148. ++$column,
  149. $count
  150. );
  151. }
  152. $row = 2;
  153. $column = 0;
  154. $availableIcon = Display::return_icon('bullet_green.png', get_lang('Available'));
  155. $notAvailableIcon = Display::return_icon('bullet_red.png', get_lang('Not available'));
  156. foreach ($students as $studentId) {
  157. $userInfo = api_get_user_info($studentId);
  158. $name = $userInfo['complete_name'];
  159. if ($userId == $studentId) {
  160. if ($action !== 'edit') {
  161. $name .= Display::url(
  162. Display::return_icon('edit.png', get_lang('Edit')),
  163. $urlEdit
  164. );
  165. }
  166. $rowColumn = 1;
  167. foreach ($questions as $item) {
  168. $checked = '';
  169. $html = '';
  170. if (isset($answerList[$item['question_id']][$studentId])) {
  171. $checked = $availableIcon;
  172. if (empty($answerList[$item['question_id']][$studentId])) {
  173. $checked = $notAvailableIcon;
  174. }
  175. if ($action === 'edit') {
  176. $checked = '';
  177. if ($answerList[$item['question_id']][$studentId] == 1) {
  178. $checked = 'checked';
  179. }
  180. }
  181. }
  182. if ($action === 'edit') {
  183. $html = '<div class="alert alert-info"><input
  184. id="'.$item['question_id'].'"
  185. name="options['.$item['question_id'].']"
  186. class="question" '.$checked.'
  187. type="checkbox"
  188. /></div>';
  189. } else {
  190. $html = $checked;
  191. }
  192. $table->setHeaderContents(
  193. $row,
  194. $rowColumn,
  195. $html
  196. );
  197. $rowColumn++;
  198. }
  199. } else {
  200. $rowColumn = 1;
  201. foreach ($questions as $item) {
  202. $checked = '';
  203. if (isset($answerList[$item['question_id']][$studentId])) {
  204. $checked = $availableIcon;
  205. if (empty($answerList[$item['question_id']][$studentId])) {
  206. $checked = $notAvailableIcon;
  207. }
  208. }
  209. $table->setHeaderContents(
  210. $row,
  211. $rowColumn,
  212. $checked
  213. );
  214. $rowColumn++;
  215. }
  216. }
  217. $column = 0;
  218. $table->setCellContents($row, $column, $name);
  219. $row++;
  220. }
  221. if ($action === 'edit') {
  222. $content .= '<form name="meeting" action="'.$urlEdit.'" method="post">';
  223. }
  224. $content .= $table->toHtml();
  225. if ($action === 'edit') {
  226. $content .= '<div class="pull-right">
  227. <button name="submit" type="submit" class="btn btn-primary btn-lg">'.get_lang('Save').'</button></div>';
  228. $content .= '</form>';
  229. }
  230. $actions = '';
  231. if (api_is_allowed_to_edit()) {
  232. $actions .= Display::url(
  233. Display::return_icon('edit.png', get_lang('Edit survey'), '', ICON_SIZE_MEDIUM),
  234. api_get_path(WEB_CODE_PATH).'survey/edit_meeting.php?'.api_get_cidreq().'&action=edit&survey_id='.$surveyId
  235. );
  236. $actions .= Display::url(
  237. Display::return_icon('delete.png', get_lang('Delete survey'), '', ICON_SIZE_MEDIUM),
  238. api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq().'&action=delete&survey_id='.$surveyId,
  239. ['onclick' => 'javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('Delete survey').'?', ENT_QUOTES)).'\')) return false;']
  240. );
  241. $actions .= Display::url(
  242. Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_MEDIUM),
  243. api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?'.api_get_cidreq().'&survey_id='.$surveyId
  244. );
  245. }
  246. $template->assign('actions', Display::toolbarAction('toolbar', [$actions]));
  247. $template->assign('content', $content);
  248. $template->display_one_col_template();