displaygradebook.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class DisplayGradebook
  5. * @package chamilo.gradebook
  6. */
  7. class DisplayGradebook
  8. {
  9. /**
  10. * Displays the header for the result page containing the navigation tree and links
  11. * @param $evalobj
  12. * @param $selectcat
  13. * @param $shownavbar 1=show navigation bar
  14. * @param $forpdf only output for pdf file
  15. */
  16. public static function display_header_result($evalobj, $selectcat, $page)
  17. {
  18. $header = null;
  19. if (api_is_allowed_to_edit(null, true)) {
  20. $header = '<div class="actions">';
  21. if ($page != 'statistics') {
  22. $header .= '<a href="' . Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . $selectcat . '&'.api_get_cidreq().'">' .
  23. Display::return_icon(('back.png'), get_lang('FolderView'), '', ICON_SIZE_MEDIUM) . '</a>';
  24. if ($evalobj->get_course_code() == null) {
  25. } elseif (!$evalobj->has_results()) {
  26. $header .= '<a href="gradebook_add_result.php?'.api_get_cidreq().'&selectcat=' . $selectcat . '&selecteval=' . $evalobj->get_id() . '">
  27. ' . Display::return_icon('evaluation_rate.png', get_lang('AddResult'), '', ICON_SIZE_MEDIUM) . '</a>';
  28. }
  29. if (api_is_platform_admin() || $evalobj->is_locked() == false) {
  30. $header .= '<a href="' . api_get_self() . '?'.api_get_cidreq().'&selecteval=' . $evalobj->get_id() . '&import=">' .
  31. Display::return_icon('import_evaluation.png', get_lang('ImportResult'), '', ICON_SIZE_MEDIUM) . '</a>';
  32. }
  33. if ($evalobj->has_results()) {
  34. $header .= '<a href="' . api_get_self() . '?'.api_get_cidreq().'&selecteval=' . $evalobj->get_id() . '&export=">' .
  35. Display::return_icon('export_evaluation.png', get_lang('ExportResult'), '', ICON_SIZE_MEDIUM) . '</a>';
  36. if (api_is_platform_admin() || $evalobj->is_locked() == false) {
  37. $header .= '<a href="gradebook_edit_result.php?'.api_get_cidreq().'&selecteval=' . $evalobj->get_id() . '">' .
  38. Display::return_icon('edit.png', get_lang('EditResult'), '', ICON_SIZE_MEDIUM) . '</a>';
  39. $header .= '<a href="' . api_get_self() . '?'.api_get_cidreq().'&selecteval=' . $evalobj->get_id() . '&deleteall=" onclick="return confirmationall();">' .
  40. Display::return_icon('delete.png', get_lang('DeleteResult'), '', ICON_SIZE_MEDIUM) . '</a>';
  41. }
  42. }
  43. $header .= '<a href="' . api_get_self() . '?'.api_get_cidreq().'&print=&selecteval=' . $evalobj->get_id() . '" target="_blank">' .
  44. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM) . '</a>';
  45. } else {
  46. $header .= '<a href="gradebook_view_result.php?'.api_get_cidreq().'&selecteval=' . Security::remove_XSS($_GET['selecteval']) . '"> ' .
  47. Display::return_icon(('back.png'), get_lang('FolderView'), '', ICON_SIZE_MEDIUM) . '</a>';
  48. }
  49. $header .= '</div>';
  50. }
  51. if ($evalobj->is_visible() == '1') {
  52. $visible = get_lang('Yes');
  53. } else {
  54. $visible = get_lang('No');
  55. }
  56. $scoredisplay = ScoreDisplay :: instance();
  57. $student_score = '';
  58. $average = "";
  59. if (($evalobj->has_results())) { // TODO this check needed ?
  60. $score = $evalobj->calc_score();
  61. if ($score != null) {
  62. $average = get_lang('Average') . ' :<b> ' . $scoredisplay->display_score($score, SCORE_AVERAGE) . '</b>';
  63. $student_score = $evalobj->calc_score(api_get_user_id());
  64. $student_score = Display::tag(
  65. 'h3',
  66. get_lang('Score') . ': ' . $scoredisplay->display_score($student_score, SCORE_DIV_PERCENT)
  67. );
  68. }
  69. }
  70. $description = "";
  71. if (!$evalobj->get_description() == '') {
  72. $description = get_lang('Description') . ' :<b> ' . $evalobj->get_description() . '</b><br>';
  73. }
  74. if ($evalobj->get_course_code() == null) {
  75. $course = get_lang('CourseIndependent');
  76. } else {
  77. $course = CourseManager::getCourseNameFromCode($evalobj->get_course_code());
  78. }
  79. $evalinfo = '<table width="100%" border="0"><tr><td>';
  80. $evalinfo .= '<h2>' . $evalobj->get_name() . '</h2><hr>';
  81. $evalinfo .= $description;
  82. $evalinfo .= get_lang('Course') . ' :<b> ' . $course . '</b><br />';
  83. $evalinfo .= get_lang('QualificationNumeric') . ' :<b> ' . $evalobj->get_max() . '</b><br>' . $average;
  84. if (!api_is_allowed_to_edit()) {
  85. $evalinfo .= $student_score;
  86. }
  87. if (!$evalobj->has_results()) {
  88. $evalinfo .= '<br /><i>' . get_lang('NoResultsInEvaluation') . '</i>';
  89. } elseif ($scoredisplay->is_custom() && api_get_self() != '/main/gradebook/gradebook_statistics.php') {
  90. if (api_is_allowed_to_edit(null, true)) {
  91. if ($page != 'statistics') {
  92. //$evalinfo .= '<br /><br /><a href="gradebook_view_result.php?selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '.Display::return_icon(('evaluation_rate.png'),get_lang('ViewResult'),'',ICON_SIZE_MEDIUM) . '</a>';
  93. }
  94. }
  95. }
  96. if ($page != 'statistics') {
  97. if (api_is_allowed_to_edit(null, true)) {
  98. $evalinfo .= '<br /><a href="gradebook_statistics.php?' . api_get_cidreq() . '&selecteval=' . Security::remove_XSS($_GET['selecteval']) . '"> ' .
  99. Display::return_icon('statistics.png', get_lang('ViewStatistics'), '', ICON_SIZE_MEDIUM) . '</a>';
  100. }
  101. }
  102. $evalinfo .= '</td><td>'.Display::return_icon('tutorial.gif', '', ['style' => 'float:right; position:relative;']).'</td></table>';
  103. echo $evalinfo;
  104. echo $header;
  105. }
  106. /**
  107. * Displays the header for the flatview page containing filters
  108. * @param $catobj
  109. * @param $showeval
  110. * @param $showlink
  111. */
  112. public function display_header_flatview($catobj, $showeval, $showlink, $simple_search_form)
  113. {
  114. $header = '<table border="0" cellpadding="5">';
  115. $header .= '<td style="vertical-align: top;"><a href="' . Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '">' . Display::return_icon('gradebook.gif') . get_lang('Gradebook') . '</a></td>';
  116. $header .= '<td style="vertical-align: top;">' . get_lang('FilterCategory') . '</td><td style="vertical-align: top;"><form name="selector"><select name="selectcat" onchange="document.selector.submit()">';
  117. $cats = Category :: load();
  118. $tree = $cats[0]->get_tree();
  119. unset($cats);
  120. foreach ($tree as $cat) {
  121. for ($i = 0; $i < $cat[2]; $i++) {
  122. $line .= '&mdash;';
  123. }
  124. if ($_GET['selectcat'] == $cat[0]) {
  125. $header .= '<option selected="selected" value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>';
  126. } else {
  127. $header .= '<option value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>';
  128. }
  129. $line = '';
  130. }
  131. $header .= '</td></select></form>';
  132. if (!$catobj->get_id() == '0') {
  133. $header .= '<td style="vertical-align: top;"><a href="' . api_get_self() . '?selectcat=' . $catobj->get_parent_id() . '">';
  134. $header .= Display::return_icon('gradebook.gif', get_lang('Up'));
  135. $header .= '</a></td>';
  136. }
  137. $header .= '<td style="vertical-align: top;">' . $simple_search_form->toHtml() . '</td>';
  138. $header .= '<td style="vertical-align: top;">
  139. <a href="' . api_get_self() . '?exportpdf=&offset=' . Security::remove_XSS($_GET['offset']) . '&search=' . Security::remove_XSS($_GET['search']) . '&selectcat=' . $catobj->get_id() . '">
  140. '.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
  141. ' . get_lang('ExportPDF') . '</a>';
  142. $header .= '<td style="vertical-align: top;">
  143. <a href="' . api_get_self() . '?print=&selectcat=' . $catobj->get_id() . '" target="_blank">
  144. '.Display::return_icon('printer.png', get_lang('Print'), [], ICON_SIZE_MEDIUM).'
  145. ' . get_lang('Print') . '</a>';
  146. $header .= '</td></tr></table>';
  147. if (!$catobj->get_id() == '0') {
  148. $header .= '<table border="0" cellpadding="5"><tr><td><form name="itemfilter" method="post" action="' . api_get_self() . '?selectcat=' . $catobj->get_id() . '">
  149. <input type="checkbox" name="showeval" onclick="document.itemfilter.submit()" ' . (($showeval == '1') ? 'checked' : '') . '>Show Evaluations &nbsp;';
  150. $header .= '<input type="checkbox" name="showlink" onclick="document.itemfilter.submit()" ' . (($showlink == '1') ? 'checked' : '') . '>' . get_lang('ShowLinks') . '</form></td></tr></table>';
  151. }
  152. if (isset($_GET['search'])) {
  153. $header .= '<b>' . get_lang('SearchResults') . ' :</b>';
  154. }
  155. echo $header;
  156. }
  157. /**
  158. * Displays the header for the flatview page containing filters
  159. * @param $catobj
  160. * @param $showeval
  161. * @param $showlink
  162. */
  163. public static function display_header_reduce_flatview($catobj, $showeval, $showlink, $simple_search_form)
  164. {
  165. $header = '<div class="actions">';
  166. if ($catobj->get_parent_id() == 0) {
  167. $select_cat = $catobj->get_id();
  168. $url = Security::remove_XSS($_SESSION['gradebook_dest']);
  169. } else {
  170. $select_cat = $catobj->get_parent_id();
  171. $url = 'gradebook_flatview.php';
  172. }
  173. $header .= '<a href="' . $url . '?' . api_get_cidreq() . '&selectcat=' . $select_cat . '">' .
  174. Display::return_icon('back.png', get_lang('FolderView'), '', ICON_SIZE_MEDIUM) . '</a>';
  175. $pageNum = isset($_GET['flatviewlist_page_nr']) ? intval($_GET['flatviewlist_page_nr']) : null;
  176. $perPage = isset($_GET['flatviewlist_per_page']) ? intval($_GET['flatviewlist_per_page']) : null;
  177. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  178. $exportCsvUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
  179. 'export_format' => 'csv',
  180. 'export_report' => 'export_report',
  181. 'selectcat' => $catobj->get_id()
  182. ]);
  183. $header .= Display::url(
  184. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM),
  185. $exportCsvUrl
  186. );
  187. $exportXlsUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
  188. 'export_format' => 'xls',
  189. 'export_report' => 'export_report',
  190. 'selectcat' => $catobj->get_id()
  191. ]);
  192. $header .= Display::url(
  193. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM),
  194. $exportXlsUrl
  195. );
  196. $exportDocUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
  197. 'export_format' => 'doc',
  198. 'export_report' => 'export_report',
  199. 'selectcat' => $catobj->get_id()
  200. ]);
  201. $header .= Display::url(
  202. Display::return_icon('export_doc.png', get_lang('ExportAsDOC'), '', ICON_SIZE_MEDIUM),
  203. $exportDocUrl
  204. );
  205. $exportPrintUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
  206. 'print' => '',
  207. 'selectcat' => $catobj->get_id(),
  208. ]);
  209. $header .= Display::url(
  210. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM),
  211. $exportPrintUrl,
  212. ['target' => '_blank']
  213. );
  214. $exportPdfUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
  215. 'exportpdf' => '',
  216. 'selectcat' => $catobj->get_id(),
  217. 'offset' => $offset,
  218. 'flatviewlist_page_nr' => $pageNum,
  219. 'flatviewlist_per_page' => $perPage
  220. ]);
  221. $header .= Display::url(
  222. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM),
  223. $exportPdfUrl
  224. );
  225. $header .= '</div>';
  226. echo $header;
  227. }
  228. /**
  229. * @param Category $catobj
  230. * @param $showtree
  231. * @param $selectcat
  232. * @param $is_course_admin
  233. * @param $is_platform_admin
  234. * @param $simple_search_form
  235. * @param bool $show_add_qualification
  236. * @param bool $show_add_link
  237. */
  238. public function display_header_gradebook_per_gradebook($catobj, $showtree, $selectcat, $is_course_admin, $is_platform_admin, $simple_search_form, $show_add_qualification = true, $show_add_link = true)
  239. {
  240. // Student
  241. $status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
  242. $objcat = new Category();
  243. $course_id = CourseManager::get_course_by_category($selectcat);
  244. $message_resource = $objcat->show_message_resource_delete($course_id);
  245. if (!$is_course_admin && $status <> 1 && $selectcat <> 0) {
  246. $user_id = api_get_user_id();
  247. $user = api_get_user_info($user_id);
  248. $catcourse = Category :: load($catobj->get_id());
  249. $scoredisplay = ScoreDisplay :: instance();
  250. $scorecourse = $catcourse[0]->calc_score($user_id);
  251. // generating the total score for a course
  252. $allevals = $catcourse[0]->get_evaluations($user_id, true);
  253. $alllinks = $catcourse[0]->get_links($user_id, true);
  254. $evals_links = array_merge($allevals, $alllinks);
  255. $item_value = 0;
  256. $item_total = 0;
  257. for ($count = 0; $count < count($evals_links); $count++) {
  258. $item = $evals_links[$count];
  259. $score = $item->calc_score($user_id);
  260. $my_score_denom = ($score[1] == 0) ? 1 : $score[1];
  261. $item_value+=$score[0] / $my_score_denom * $item->get_weight();
  262. $item_total+=$item->get_weight();
  263. }
  264. $item_value = number_format($item_value, 2, '.', ' ');
  265. $total_score = array($item_value, $item_total);
  266. $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
  267. $cattotal = Category :: load(0);
  268. $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
  269. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  270. $scoreinfo = get_lang('StatsStudent') . ' :<b> ' . api_get_person_name($user['firstname'], $user['lastname']) . '</b><br />';
  271. if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search']))) {
  272. $scoreinfo.= '<h2>' . get_lang('Total') . ' : ' . $scorecourse_display . '</h2>';
  273. }
  274. Display :: display_normal_message($scoreinfo, false);
  275. }
  276. // show navigation tree and buttons?
  277. $header = '<div class="actions"><table border=0>';
  278. if (($showtree == '1') || (isset($_GET['studentoverview']))) {
  279. $header .= '<tr>';
  280. if (!$selectcat == '0') {
  281. $header .= '<td style=" "><a href="' . api_get_self() . '?selectcat=' . $catobj->get_parent_id() . '">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('RootCat'), '', ICON_SIZE_MEDIUM) . '</a></td>';
  282. }
  283. $header .= '<td style=" ">' . get_lang('CurrentCategory') . '</td>' .
  284. '<td style=" "><form name="selector"><select name="selectcat" onchange="document.selector.submit()">';
  285. $cats = Category :: load();
  286. $tree = $cats[0]->get_tree();
  287. unset($cats);
  288. foreach ($tree as $cat) {
  289. for ($i = 0; $i < $cat[2]; $i++) {
  290. $line .= '&mdash;';
  291. }
  292. $line = isset($line) ? $line : '';
  293. if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) {
  294. $header .= '<option selected value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>';
  295. } else {
  296. $header .= '<option value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>';
  297. }
  298. $line = '';
  299. }
  300. $header .= '</select></form></td>';
  301. if (!empty($simple_search_form) && $message_resource === false) {
  302. $header .= '<td style="vertical-align: top;">' . $simple_search_form->toHtml() . '</td>';
  303. } else {
  304. $header .= '<td></td>';
  305. }
  306. if ($is_course_admin && $message_resource === false && $_GET['selectcat'] != 0) {
  307. } elseif (!(isset($_GET['studentoverview']))) {
  308. } else {
  309. $header .= '<td style="vertical-align: top;"><a href="' . api_get_self() . '?' . api_get_cidreq() . '&studentoverview=&exportpdf=&selectcat=' . $catobj->get_id() . '" target="_blank">
  310. '.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
  311. ' . get_lang('ExportPDF') . '</a>';
  312. }
  313. $header .= '</td></tr>';
  314. }
  315. $header.='</table></div>';
  316. // for course admin & platform admin add item buttons are added to the header
  317. $header .= '<div class="actions">';
  318. $my_category = $catobj->shows_all_information_an_category($catobj->get_id());
  319. $user_id = api_get_user_id();
  320. $course_code = $my_category->getCourse()->getCode();
  321. $courseInfo = api_get_course_info($course_code);
  322. $courseId = $courseInfo['real_id'];
  323. $status_user = api_get_status_of_user_in_course($user_id, $courseId);
  324. if (api_is_allowed_to_edit(null, true)) {
  325. if ($selectcat == '0') {
  326. } else {
  327. $my_category = $catobj->shows_all_information_an_category($catobj->get_id());
  328. $my_api_cidreq = api_get_cidreq();
  329. if ($my_api_cidreq == '') {
  330. $my_api_cidreq = 'cidReq=' . $my_category->getCourse()->getcode();
  331. }
  332. if (!$message_resource) {
  333. $myname = $catobj->shows_all_information_an_category($catobj->get_id());
  334. $my_course_id = api_get_course_id();
  335. $my_file = substr($_SESSION['gradebook_dest'], 0, 5);
  336. $header .= '<td style="vertical-align: top;"><a href="gradebook_flatview.php?' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '">' .
  337. Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM) . '</a>';
  338. $header .= '<td style="vertical-align: top;"><a href="gradebook_display_certificate.php?' . $my_api_cidreq . '&amp;cat_id=' . (int) $_GET['selectcat'] . '">' .
  339. Display::return_icon('certificate_list.png', get_lang('GradebookSeeListOfStudentsCertificates'), '', ICON_SIZE_MEDIUM) . '</a>';
  340. $visibility_icon = ($catobj->is_visible() == 0) ? 'invisible' : 'visible';
  341. $visibility_command = ($catobj->is_visible() == 0) ? 'set_visible' : 'set_invisible';
  342. //Right icons
  343. $modify_icons = '<a href="gradebook_edit_cat.php?editcat=' . $catobj->get_id() . '&cidReq=' . $catobj->get_course_code() . '&id_session='.$catobj->get_session_id(). '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM) . '</a>';
  344. if ($catobj->get_name() != api_get_course_id()) {
  345. $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletecat=' . $catobj->get_id() . '&amp;selectcat=0&amp;cidReq=' . $catobj->get_course_code() . '" onclick="return confirmation();">' . Display::return_icon('delete.png', get_lang('DeleteAll'), '', ICON_SIZE_MEDIUM) . '</a>';
  346. }
  347. $header .= Display::div($modify_icons, array('class' => 'right'));
  348. }
  349. }
  350. } elseif (isset($_GET['search'])) {
  351. $header .= '<b>' . get_lang('SearchResults') . ' :</b>';
  352. }
  353. $header .= '</div>';
  354. echo $header;
  355. }
  356. /**
  357. * Displays the header for the gradebook containing the navigation tree and links
  358. * @param Category $catobj
  359. * @param int $showtree '1' will show the browse tree and naviation buttons
  360. * @param boolean $is_course_admin
  361. * @param boolean $is_platform_admin
  362. * @param boolean Whether to show or not the link to add a new qualification
  363. * (we hide it in case of the course-embedded tool where we have only one
  364. * calification per course or session)
  365. * @param boolean Whether to show or not the link to add a new item inside
  366. * the qualification (we hide it in case of the course-embedded tool
  367. * where we have only one calification per course or session)
  368. * @return void Everything is printed on screen upon closing
  369. */
  370. static function header(
  371. $catobj,
  372. $showtree,
  373. $selectcat,
  374. $is_course_admin,
  375. $is_platform_admin,
  376. $simple_search_form,
  377. $show_add_qualification = true,
  378. $show_add_link = true,
  379. $certificateLinkInfo = null
  380. ) {
  381. $userId = api_get_user_id();
  382. $courseCode = api_get_course_id();
  383. $courseId = api_get_course_int_id();
  384. $sessionId = api_get_session_id();
  385. // Student.
  386. $status = CourseManager::get_user_in_course_status($userId, $courseCode);
  387. if (!empty($sessionId)) {
  388. $sessionStatus = SessionManager::get_user_status_in_course_session(
  389. $userId,
  390. $courseId,
  391. $sessionId
  392. );
  393. }
  394. $objcat = new Category();
  395. $course_id = CourseManager::get_course_by_category($selectcat);
  396. $message_resource = $objcat->show_message_resource_delete($course_id);
  397. $grade_model_id = $catobj->get_grade_model_id();
  398. $header = null;
  399. //@todo move these in a function
  400. $sum_categories_weight_array = array();
  401. if (isset($catobj) && !empty($catobj)) {
  402. $categories = Category::load(
  403. null,
  404. null,
  405. null,
  406. $catobj->get_id(),
  407. null,
  408. $sessionId
  409. );
  410. if (!empty($categories)) {
  411. foreach ($categories as $category) {
  412. $sum_categories_weight_array[$category->get_id()] = $category->get_weight();
  413. }
  414. } else {
  415. $sum_categories_weight_array[$catobj->get_id()] = $catobj->get_weight();
  416. }
  417. }
  418. if (!$is_course_admin && ($status <> 1 || $sessionStatus == 0) && $selectcat <> 0) {
  419. $catcourse = Category::load($catobj->get_id());
  420. /** @var Category $category */
  421. $category = $catcourse[0];
  422. $main_weight = $category->get_weight();
  423. $scoredisplay = ScoreDisplay :: instance();
  424. $allevals = $category->get_evaluations($userId, true);
  425. $alllinks = $category->get_links($userId, true);
  426. $allEvalsLinks = array_merge($allevals, $alllinks);
  427. $item_value_total = 0;
  428. $scoreinfo = null;
  429. for ($count = 0; $count < count($allEvalsLinks); $count++) {
  430. $item = $allEvalsLinks[$count];
  431. $score = $item->calc_score($userId);
  432. if (!empty($score)) {
  433. $divide = $score[1] == 0 ? 1 : $score[1];
  434. $item_value = $score[0] / $divide * $item->get_weight();
  435. $item_value_total += $item_value;
  436. }
  437. }
  438. $item_total = $main_weight;
  439. $total_score = array($item_value_total, $item_total);
  440. $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
  441. if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search']))) {
  442. $aditionalButtons = null;
  443. if (!empty($certificateLinkInfo)) {
  444. $aditionalButtons .= '<div class="btn-group pull-right">';
  445. $aditionalButtons .= isset($certificateLinkInfo['certificate_link']) ? $certificateLinkInfo['certificate_link'] : '';
  446. $aditionalButtons .= isset($certificateLinkInfo['badge_link']) ? $certificateLinkInfo['badge_link'] : '';
  447. $aditionalButtons .= '</div>';
  448. }
  449. $scoreinfo .= '<strong>' . sprintf(get_lang('TotalX'), $scorecourse_display . $aditionalButtons). '</strong>';
  450. }
  451. Display :: display_normal_message($scoreinfo, false);
  452. }
  453. // show navigation tree and buttons?
  454. if (($showtree == '1') || (isset($_GET['studentoverview']))) {
  455. $header = '<div class="actions"><table>';
  456. $header .= '<tr>';
  457. if (!$selectcat == '0') {
  458. $header .= '<td><a href="' . api_get_self() . '?selectcat=' . $catobj->get_parent_id() . '">' .
  459. Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('RootCat'), '', ICON_SIZE_MEDIUM) . '</a></td>';
  460. }
  461. $header .= '<td>' . get_lang('CurrentCategory') . '</td>' .
  462. '<td><form name="selector"><select name="selectcat" onchange="document.selector.submit()">';
  463. $cats = Category :: load();
  464. $tree = $cats[0]->get_tree();
  465. unset($cats);
  466. $line = null;
  467. foreach ($tree as $cat) {
  468. for ($i = 0; $i < $cat[2]; $i++) {
  469. $line .= '&mdash;';
  470. }
  471. $line = isset($line) ? $line : '';
  472. if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) {
  473. $header .= '<option selected value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>';
  474. } else {
  475. $header .= '<option value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>';
  476. }
  477. $line = '';
  478. }
  479. $header .= '</select></form></td>';
  480. if (!empty($simple_search_form) && $message_resource === false) {
  481. $header .= '<td style="vertical-align: top;">' . $simple_search_form->toHtml() . '</td>';
  482. } else {
  483. $header .= '<td></td>';
  484. }
  485. if ($is_course_admin &&
  486. $message_resource === false &&
  487. isset($_GET['selectcat']) && $_GET['selectcat'] != 0
  488. ) {
  489. } elseif (!(isset($_GET['studentoverview']))) {
  490. } else {
  491. $header .= '<td style="vertical-align: top;"><a href="' . api_get_self() . '?' . api_get_cidreq() . '&studentoverview=&exportpdf=&selectcat=' . $catobj->get_id() . '" target="_blank">
  492. '.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
  493. ' . get_lang('ExportPDF') . '</a>';
  494. }
  495. $header .= '</td></tr>';
  496. $header .= '</table></div>';
  497. }
  498. // for course admin & platform admin add item buttons are added to the header
  499. $actionsLeft = '';
  500. $my_category = $catobj->shows_all_information_an_category($catobj->get_id());
  501. $user_id = api_get_user_id();
  502. $my_api_cidreq = api_get_cidreq();
  503. if (api_is_allowed_to_edit(null, true)) {
  504. if (empty($grade_model_id) || $grade_model_id == -1) {
  505. $actionsLeft .= '<a href="gradebook_add_cat.php?' . api_get_cidreq() . '&selectcat=' . $catobj->get_id() . '">' .
  506. Display::return_icon('new_folder.png', get_lang('AddGradebook'), array(), ICON_SIZE_MEDIUM) . '</a></td>';
  507. }
  508. if ($selectcat == '0') {
  509. } else {
  510. $my_category = $catobj->shows_all_information_an_category($catobj->get_id());
  511. if ($my_api_cidreq == '') {
  512. $my_api_cidreq = 'cidReq=' . $my_category->getCourse()->getCode();
  513. }
  514. if ($show_add_link && !$message_resource) {
  515. $actionsLeft .= '<a href="gradebook_add_eval.php?' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '" >' .
  516. Display::return_icon('new_evaluation.png', get_lang('NewEvaluation'), '', ICON_SIZE_MEDIUM) . '</a>';
  517. $cats = Category :: load($selectcat);
  518. if ($cats[0]->get_course_code() != null && !$message_resource) {
  519. $actionsLeft .= '<a href="gradebook_add_link.php?' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '">' .
  520. Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '', ICON_SIZE_MEDIUM) . '</a>';
  521. } else {
  522. $actionsLeft .= '<a href="gradebook_add_link_select_course.php?' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '">' .
  523. Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '', ICON_SIZE_MEDIUM) . '</a>';
  524. }
  525. }
  526. if (!$message_resource) {
  527. $actionsLeft .= '<a href="gradebook_flatview.php?' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '">' .
  528. Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM) . '</a>';
  529. if ($my_category->getGenerateCertificates() == 1) {
  530. $actionsLeft .= Display::url(
  531. Display::return_icon(
  532. 'certificate_list.png',
  533. get_lang('GradebookSeeListOfStudentsCertificates'),
  534. '',
  535. ICON_SIZE_MEDIUM
  536. ),
  537. "gradebook_display_certificate.php?$my_api_cidreq&cat_id=" . intval($_GET['selectcat'])
  538. );
  539. }
  540. $actionsLeft .= Display::url(
  541. Display::return_icon(
  542. 'user.png',
  543. get_lang('GradebookListOfStudentsReports'),
  544. '',
  545. ICON_SIZE_MEDIUM
  546. ),
  547. "gradebook_display_summary.php?$my_api_cidreq&selectcat=" . intval($_GET['selectcat'])
  548. );
  549. // Right icons
  550. $actionsRight = '<a href="gradebook_edit_cat.php?editcat=' . $catobj->get_id() . '&amp;cidReq=' . $catobj->get_course_code() . '&id_session='.$catobj->get_session_id(). '">' .
  551. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM) . '</a>';
  552. $actionsRight .= '<a href="../document/document.php?curdirpath=/certificates&' . $my_api_cidreq . '&origin=gradebook&selectcat=' . $catobj->get_id() . '">' .
  553. Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM) . '</a>';
  554. if (empty($categories)) {
  555. $actionsRight .= '<a href="gradebook_edit_all.php?id_session=' . api_get_session_id() . '&amp;' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '">' .
  556. Display::return_icon('percentage.png', get_lang('EditAllWeights'), '', ICON_SIZE_MEDIUM) . '</a>';
  557. }
  558. $score_display_custom = api_get_setting(
  559. 'gradebook.gradebook_score_display_custom'
  560. );
  561. if (api_get_setting(
  562. 'gradebook.teachers_can_change_score_settings'
  563. ) == 'true' && $score_display_custom !== 'false' && $score_display_custom['my_display_custom'] == 'true'
  564. ) {
  565. $actionsRight .= '<a href="gradebook_scoring_system.php?' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '">' .
  566. Display::return_icon('ranking.png', get_lang('ScoreEdit'), '', ICON_SIZE_MEDIUM) . '</a>';
  567. }
  568. }
  569. }
  570. } elseif (isset($_GET['search'])) {
  571. echo $header = '<b>' . get_lang('SearchResults') . ' :</b>';
  572. }
  573. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  574. api_get_user_id(),
  575. api_get_course_info()
  576. );
  577. if ($isDrhOfCourse) {
  578. $$actionsLeft .= '<a href="gradebook_flatview.php?' . $my_api_cidreq . '&selectcat=' . $catobj->get_id() . '">' .
  579. Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM) . '</a>';
  580. }
  581. if (api_is_allowed_to_edit(null, true)){
  582. echo $toolbar = Display::toolbarAction('gradebook-actions', array(0 => $actionsLeft, 1 => $actionsRight ));
  583. }
  584. if (api_is_allowed_to_edit(null, true)) {
  585. $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0;
  586. $weight = '<strong>' . get_lang('TotalWeight') . ' : </strong>' . $weight;
  587. $min_certification = (intval($catobj->get_certificate_min_score() > 0) ? $catobj->get_certificate_min_score() : 0);
  588. $min_certification = get_lang('CertificateMinScore') . ' : ' . $min_certification;
  589. $edit_icon = '<a href="gradebook_edit_cat.php?editcat=' . $catobj->get_id() . '&amp;cidReq=' . $catobj->get_course_code() . '&id_session='.$catobj->get_session_id(). '">' .
  590. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>';
  591. //$msg = Display::tag('h3', $weight.' - '.$min_certification);
  592. $msg = $weight . ' - ' . $min_certification . $edit_icon;
  593. //@todo show description
  594. $description = (($catobj->get_description() == "" || is_null($catobj->get_description())) ? '' : '<strong>' . get_lang('GradebookDescriptionLog') . '</strong>' . ': ' . $catobj->get_description());
  595. Display::display_normal_message($msg, false);
  596. if (!empty($description)) {
  597. echo Display::div($description, array());
  598. }
  599. }
  600. }
  601. /**
  602. * @param Category $catobj
  603. * @param $is_course_admin
  604. * @param $is_platform_admin
  605. * @param $simple_search_form
  606. * @param bool $show_add_qualification
  607. * @param bool $show_add_link
  608. */
  609. public function display_reduce_header_gradebook($catobj, $is_course_admin, $is_platform_admin, $simple_search_form, $show_add_qualification = true, $show_add_link = true)
  610. {
  611. //student
  612. if (!$is_course_admin) {
  613. $user = api_get_user_info(api_get_user_id());
  614. $catcourse = Category :: load($catobj->get_id());
  615. $scoredisplay = ScoreDisplay :: instance();
  616. $scorecourse = $catcourse[0]->calc_score(api_get_user_id());
  617. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  618. $cattotal = Category :: load(0);
  619. $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
  620. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  621. $scoreinfo = get_lang('StatsStudent') . ' :<b> ' . $user['complete_name']. '</b><br />';
  622. if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search'])))
  623. $scoreinfo.= '<br />' . get_lang('TotalForThisCategory') . ' : <b>' . $scorecourse_display . '</b>';
  624. $scoreinfo.= '<br />' . get_lang('Total') . ' : <b>' . $scoretotal_display . '</b>';
  625. Display :: display_normal_message($scoreinfo, false);
  626. }
  627. // show navigation tree and buttons?
  628. $header = '<div class="actions">';
  629. if ($is_course_admin) {
  630. $header .= '<a href="gradebook_flatview.php?' . api_get_cidreq() . '&selectcat=' . $catobj->get_id() . '">' . Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM) . '</a>';
  631. $header .= '<a href="gradebook_scoring_system.php?' . api_get_cidreq() . '&selectcat=' . $catobj->get_id() . '">' . Display::return_icon('settings.png', get_lang('ScoreEdit'), '', ICON_SIZE_MEDIUM) . '</a>';
  632. } elseif (!(isset($_GET['studentoverview']))) {
  633. $header .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&studentoverview=&selectcat=' . $catobj->get_id() . '">' . Display::return_icon('view_list.gif', get_lang('FlatView')) . ' ' . get_lang('FlatView') . '</a>';
  634. } else {
  635. $header .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&studentoverview=&exportpdf=&selectcat=' . $catobj->get_id() . '" target="_blank">' . Display::return_icon('pdf.png', get_lang('ExportPDF'), '', ICON_SIZE_MEDIUM) . '</a>';
  636. }
  637. $header.='</div>';
  638. echo $header;
  639. }
  640. /**
  641. * @param int $userid
  642. */
  643. public static function display_header_user($userid)
  644. {
  645. $select_cat = intval($_GET['selectcat']);
  646. $user_id = $userid;
  647. $user = api_get_user_info($user_id);
  648. $catcourse = Category :: load($select_cat);
  649. $scoredisplay = ScoreDisplay :: instance();
  650. $scorecourse = $catcourse[0]->calc_score($user_id);
  651. // generating the total score for a course
  652. $allevals = $catcourse[0]->get_evaluations($user_id, true);
  653. $alllinks = $catcourse[0]->get_links($user_id, true);
  654. $evals_links = array_merge($allevals, $alllinks);
  655. $item_value = 0;
  656. $item_total = 0;
  657. for ($count = 0; $count < count($evals_links); $count++) {
  658. $item = $evals_links[$count];
  659. $score = $item->calc_score($user_id);
  660. $my_score_denom = ($score[1] == 0) ? 1 : $score[1];
  661. $item_value+=$score[0] / $my_score_denom * $item->get_weight();
  662. $item_total+=$item->get_weight();
  663. //$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
  664. }
  665. $item_value = number_format($item_value, 2, '.', ' ');
  666. $total_score = array($item_value, $item_total);
  667. $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
  668. //$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  669. $cattotal = Category :: load(0);
  670. $scoretotal = $cattotal[0]->calc_score($user_id);
  671. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  672. $imageUrl = UserManager::getUserPicture($userid);
  673. $info = '<div class="row"><div class="col-md-3">';
  674. $info .= '<div class="thumbnail"><img src="' . $imageUrl . '" /></div>';
  675. $info .= '</div>';
  676. $info .= '<div class="col-md-6">';
  677. $info .= get_lang('Name') . ' : <a target="_blank" href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php?u=' . $userid . '"> ' .
  678. $user['complete_name'] . '</a><br />';
  679. if (api_get_setting('display.show_email_addresses') == 'true') {
  680. $info .= get_lang('Email') . ' : <a href="mailto:' . $user['email'] . '">' . $user['email'] . '</a><br />';
  681. }
  682. $info .= get_lang('TotalUser') . ' : <b>' . $scorecourse_display . '</b>';
  683. $info .= '</div>';
  684. $info .= '</div>';
  685. echo $info;
  686. }
  687. }