displaygradebook.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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) && !$evalobj->has_results()) {
  25. $header .= '<a href="gradebook_add_result.php?'.api_get_cidreq().'&selectcat='.$selectcat.'&selecteval='.$evalobj->get_id().'">
  26. ' . Display::return_icon('evaluation_rate.png', get_lang('AddResult'), '', ICON_SIZE_MEDIUM).'</a>';
  27. }
  28. if (api_is_platform_admin() || $evalobj->is_locked() == false) {
  29. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&import=">'.
  30. Display::return_icon('import_evaluation.png', get_lang('ImportResult'), '', ICON_SIZE_MEDIUM).'</a>';
  31. }
  32. if ($evalobj->has_results()) {
  33. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&export=">'.
  34. Display::return_icon('export_evaluation.png', get_lang('ExportResult'), '', ICON_SIZE_MEDIUM).'</a>';
  35. if (api_is_platform_admin() || $evalobj->is_locked() == false) {
  36. $header .= '<a href="gradebook_edit_result.php?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'">'.
  37. Display::return_icon('edit.png', get_lang('EditResult'), '', ICON_SIZE_MEDIUM).'</a>';
  38. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&deleteall=" onclick="return confirmationall();">'.
  39. Display::return_icon('delete.png', get_lang('DeleteResult'), '', ICON_SIZE_MEDIUM).'</a>';
  40. }
  41. }
  42. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&print=&selecteval='.$evalobj->get_id().'" target="_blank">'.
  43. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  44. } else {
  45. $header .= '<a href="gradebook_view_result.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '.
  46. Display::return_icon(('back.png'), get_lang('FolderView'), '', ICON_SIZE_MEDIUM).'</a>';
  47. }
  48. $header .= '</div>';
  49. }
  50. if ($evalobj->is_visible() == '1') {
  51. $visible = get_lang('Yes');
  52. } else {
  53. $visible = get_lang('No');
  54. }
  55. $scoredisplay = ScoreDisplay::instance();
  56. $student_score = '';
  57. $average = '';
  58. if (($evalobj->has_results())) {
  59. // 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. }
  90. /* Code comment without reason
  91. elseif ($scoredisplay->is_custom() && api_get_self() != '/main/gradebook/gradebook_statistics.php') {
  92. if (api_is_allowed_to_edit(null, true)) {
  93. if ($page != 'statistics') {
  94. //$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>';
  95. }
  96. }
  97. }
  98. */
  99. if ($page != 'statistics') {
  100. if (api_is_allowed_to_edit(null, true)) {
  101. $evalinfo .= '<br /><a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '.
  102. Display::return_icon('statistics.png', get_lang('ViewStatistics'), '', ICON_SIZE_MEDIUM).'</a>';
  103. }
  104. }
  105. $evalinfo .= '</td><td>'.Display::return_icon('tutorial.gif', '', ['style' => 'float:right; position:relative;']).'</td></table>';
  106. echo $evalinfo;
  107. echo $header;
  108. }
  109. /**
  110. * Displays the header for the flatview page containing filters
  111. * @param $catobj
  112. * @param $showeval
  113. * @param $showlink
  114. */
  115. public static function display_header_reduce_flatview($catobj, $showeval, $showlink, $simple_search_form)
  116. {
  117. $header = '<div class="actions">';
  118. if ($catobj->get_parent_id() == 0) {
  119. $select_cat = $catobj->get_id();
  120. $url = Security::remove_XSS($_SESSION['gradebook_dest']);
  121. } else {
  122. $select_cat = $catobj->get_parent_id();
  123. $url = 'gradebook_flatview.php';
  124. }
  125. $header .= '<a href="'.$url.'?'.api_get_cidreq().'&selectcat='.$select_cat.'">'.
  126. Display::return_icon('back.png', get_lang('FolderView'), '', ICON_SIZE_MEDIUM).'</a>';
  127. $pageNum = isset($_GET['flatviewlist_page_nr']) ? intval($_GET['flatviewlist_page_nr']) : null;
  128. $perPage = isset($_GET['flatviewlist_per_page']) ? intval($_GET['flatviewlist_per_page']) : null;
  129. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  130. $exportCsvUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  131. 'export_format' => 'csv',
  132. 'export_report' => 'export_report',
  133. 'selectcat' => $catobj->get_id()
  134. ]);
  135. $header .= Display::url(
  136. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM),
  137. $exportCsvUrl
  138. );
  139. $exportXlsUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  140. 'export_format' => 'xls',
  141. 'export_report' => 'export_report',
  142. 'selectcat' => $catobj->get_id()
  143. ]);
  144. $header .= Display::url(
  145. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM),
  146. $exportXlsUrl
  147. );
  148. $exportDocUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  149. 'export_format' => 'doc',
  150. 'export_report' => 'export_report',
  151. 'selectcat' => $catobj->get_id()
  152. ]);
  153. $header .= Display::url(
  154. Display::return_icon('export_doc.png', get_lang('ExportAsDOC'), '', ICON_SIZE_MEDIUM),
  155. $exportDocUrl
  156. );
  157. $exportPrintUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  158. 'print' => '',
  159. 'selectcat' => $catobj->get_id(),
  160. ]);
  161. $header .= Display::url(
  162. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM),
  163. $exportPrintUrl,
  164. ['target' => '_blank']
  165. );
  166. $exportPdfUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  167. 'exportpdf' => '',
  168. 'selectcat' => $catobj->get_id(),
  169. 'offset' => $offset,
  170. 'flatviewlist_page_nr' => $pageNum,
  171. 'flatviewlist_per_page' => $perPage
  172. ]);
  173. $header .= Display::url(
  174. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM),
  175. $exportPdfUrl
  176. );
  177. $header .= '</div>';
  178. echo $header;
  179. }
  180. /**
  181. * Displays the header for the gradebook containing the navigation tree and links
  182. * @param Category $catobj
  183. * @param int $showtree '1' will show the browse tree and naviation buttons
  184. * @param boolean $is_course_admin
  185. * @param boolean $is_platform_admin
  186. * @param boolean Whether to show or not the link to add a new qualification
  187. * (we hide it in case of the course-embedded tool where we have only one
  188. * calification per course or session)
  189. * @param boolean Whether to show or not the link to add a new item inside
  190. * the qualification (we hide it in case of the course-embedded tool
  191. * where we have only one calification per course or session)
  192. * @return void Everything is printed on screen upon closing
  193. */
  194. public static function header(
  195. $catobj,
  196. $showtree,
  197. $selectcat,
  198. $is_course_admin,
  199. $is_platform_admin,
  200. $simple_search_form,
  201. $show_add_qualification = true,
  202. $show_add_link = true,
  203. $certificateLinkInfo = null
  204. ) {
  205. $userId = api_get_user_id();
  206. $courseId = api_get_course_int_id();
  207. $sessionId = api_get_session_id();
  208. // Student.
  209. $status = CourseManager::getUserInCourseStatus($userId, $courseId);
  210. $sessionStatus = 0;
  211. if (!empty($sessionId)) {
  212. $sessionStatus = SessionManager::get_user_status_in_course_session(
  213. $userId,
  214. $courseId,
  215. $sessionId
  216. );
  217. }
  218. $objcat = new Category();
  219. $course_id = CourseManager::get_course_by_category($selectcat);
  220. $message_resource = $objcat->show_message_resource_delete($course_id);
  221. $grade_model_id = $catobj->get_grade_model_id();
  222. $header = null;
  223. if (isset($catobj) && !empty($catobj)) {
  224. $categories = Category::load(
  225. null,
  226. null,
  227. null,
  228. $catobj->get_id(),
  229. null,
  230. $sessionId
  231. );
  232. }
  233. if (!$is_course_admin && ($status <> 1 || $sessionStatus == 0) && $selectcat <> 0) {
  234. $catcourse = Category::load($catobj->get_id());
  235. /** @var Category $category */
  236. $category = $catcourse[0];
  237. $main_weight = $category->get_weight();
  238. $scoredisplay = ScoreDisplay::instance();
  239. $allevals = $category->get_evaluations($userId, true);
  240. $alllinks = $category->get_links($userId, true);
  241. $allEvalsLinks = array_merge($allevals, $alllinks);
  242. $item_value_total = 0;
  243. $scoreinfo = null;
  244. for ($count = 0; $count < count($allEvalsLinks); $count++) {
  245. $item = $allEvalsLinks[$count];
  246. $score = $item->calc_score($userId);
  247. if (!empty($score)) {
  248. $divide = $score[1] == 0 ? 1 : $score[1];
  249. $item_value = $score[0] / $divide * $item->get_weight();
  250. $item_value_total += $item_value;
  251. }
  252. }
  253. $item_total = $main_weight;
  254. $total_score = array($item_value_total, $item_total);
  255. $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
  256. if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search']))) {
  257. $aditionalButtons = null;
  258. if (!empty($certificateLinkInfo)) {
  259. $aditionalButtons .= '<div class="btn-group pull-right">';
  260. $aditionalButtons .= isset($certificateLinkInfo['certificate_link']) ? $certificateLinkInfo['certificate_link'] : '';
  261. $aditionalButtons .= isset($certificateLinkInfo['badge_link']) ? $certificateLinkInfo['badge_link'] : '';
  262. $aditionalButtons .= '</div>';
  263. }
  264. $scoreinfo .= '<strong>'.sprintf(get_lang('TotalX'), $scorecourse_display.$aditionalButtons).'</strong>';
  265. }
  266. echo Display::return_message($scoreinfo, 'normal', false);
  267. }
  268. // show navigation tree and buttons?
  269. if ($showtree == '1' || isset($_GET['studentoverview'])) {
  270. $header = '<div class="actions"><table>';
  271. $header .= '<tr>';
  272. if (!$selectcat == '0') {
  273. $header .= '<td><a href="'.api_get_self().'?selectcat='.$catobj->get_parent_id().'">'.
  274. Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('RootCat'), '', ICON_SIZE_MEDIUM).'</a></td>';
  275. }
  276. $header .= '<td>'.get_lang('CurrentCategory').'</td>'.
  277. '<td><form name="selector"><select name="selectcat" onchange="document.selector.submit()">';
  278. $cats = Category::load();
  279. $tree = $cats[0]->get_tree();
  280. unset($cats);
  281. $line = null;
  282. foreach ($tree as $cat) {
  283. for ($i = 0; $i < $cat[2]; $i++) {
  284. $line .= '&mdash;';
  285. }
  286. $line = isset($line) ? $line : '';
  287. if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) {
  288. $header .= '<option selected value='.$cat[0].'>'.$line.' '.$cat[1].'</option>';
  289. } else {
  290. $header .= '<option value='.$cat[0].'>'.$line.' '.$cat[1].'</option>';
  291. }
  292. $line = '';
  293. }
  294. $header .= '</select></form></td>';
  295. if (!empty($simple_search_form) && $message_resource === false) {
  296. $header .= '<td style="vertical-align: top;">'.$simple_search_form->toHtml().'</td>';
  297. } else {
  298. $header .= '<td></td>';
  299. }
  300. if (!($is_course_admin &&
  301. $message_resource === false &&
  302. isset($_GET['selectcat']) && $_GET['selectcat'] != 0
  303. ) && isset($_GET['studentoverview'])) {
  304. $header .= '<td style="vertical-align: top;"><a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">
  305. '.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
  306. ' . get_lang('ExportPDF').'</a>';
  307. }
  308. $header .= '</td></tr>';
  309. $header .= '</table></div>';
  310. }
  311. // for course admin & platform admin add item buttons are added to the header
  312. $actionsLeft = '';
  313. $my_api_cidreq = api_get_cidreq();
  314. if (api_is_allowed_to_edit(null, true)) {
  315. if (empty($grade_model_id) || $grade_model_id == -1) {
  316. $actionsLeft .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'.
  317. Display::return_icon('new_folder.png', get_lang('AddGradebook'), array(), ICON_SIZE_MEDIUM).'</a></td>';
  318. }
  319. if ($selectcat != '0') {
  320. $my_category = $catobj->shows_all_information_an_category($catobj->get_id());
  321. if ($my_api_cidreq == '') {
  322. $my_api_cidreq = 'cidReq='.$my_category['course_code'];
  323. }
  324. if ($show_add_link && !$message_resource) {
  325. $actionsLeft .= '<a href="gradebook_add_eval.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'" >'.
  326. Display::return_icon('new_evaluation.png', get_lang('NewEvaluation'), '', ICON_SIZE_MEDIUM).'</a>';
  327. $cats = Category::load($selectcat);
  328. if ($cats[0]->get_course_code() != null && !$message_resource) {
  329. $actionsLeft .= '<a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  330. Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '', ICON_SIZE_MEDIUM).'</a>';
  331. } else {
  332. $actionsLeft .= '<a href="gradebook_add_link_select_course.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  333. Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '', ICON_SIZE_MEDIUM).'</a>';
  334. }
  335. }
  336. if (!$message_resource) {
  337. $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  338. Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).'</a>';
  339. if ($my_category['generate_certificates'] == 1) {
  340. $actionsLeft .= Display::url(
  341. Display::return_icon(
  342. 'certificate_list.png',
  343. get_lang('GradebookSeeListOfStudentsCertificates'),
  344. '',
  345. ICON_SIZE_MEDIUM
  346. ),
  347. "gradebook_display_certificate.php?$my_api_cidreq&cat_id=".$selectcat
  348. );
  349. }
  350. $actionsLeft .= Display::url(
  351. Display::return_icon(
  352. 'user.png',
  353. get_lang('GradebookListOfStudentsReports'),
  354. '',
  355. ICON_SIZE_MEDIUM
  356. ),
  357. "gradebook_display_summary.php?$my_api_cidreq&selectcat=".$selectcat
  358. );
  359. // Right icons
  360. $actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&amp;cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
  361. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>';
  362. $actionsRight .= '<a href="../document/document.php?curdirpath=/certificates&'.$my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
  363. Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM).'</a>';
  364. if (empty($categories)) {
  365. $actionsRight .= '<a href="gradebook_edit_all.php?id_session='.api_get_session_id().'&amp;'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  366. Display::return_icon('percentage.png', get_lang('EditAllWeights'), '', ICON_SIZE_MEDIUM).'</a>';
  367. }
  368. $score_display_custom = api_get_setting('gradebook_score_display_custom');
  369. if (api_get_setting('teachers_can_change_score_settings') == 'true' && $score_display_custom['my_display_custom'] == 'true') {
  370. $actionsRight .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  371. Display::return_icon('ranking.png', get_lang('ScoreEdit'), '', ICON_SIZE_MEDIUM).'</a>';
  372. }
  373. }
  374. }
  375. } elseif (isset($_GET['search'])) {
  376. echo $header = '<b>'.get_lang('SearchResults').' :</b>';
  377. }
  378. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  379. api_get_user_id(),
  380. api_get_course_info()
  381. );
  382. if ($isDrhOfCourse) {
  383. $$actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  384. Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).'</a>';
  385. }
  386. if (api_is_allowed_to_edit(null, true)) {
  387. echo $toolbar = Display::toolbarAction('gradebook-actions', array($actionsLeft, $actionsRight));
  388. }
  389. if (api_is_allowed_to_edit(null, true)) {
  390. $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0;
  391. $weight = '<strong>'.get_lang('TotalWeight').' : </strong>'.$weight;
  392. $min_certification = (intval($catobj->get_certificate_min_score() > 0) ? $catobj->get_certificate_min_score() : 0);
  393. $min_certification = get_lang('CertificateMinScore').' : '.$min_certification;
  394. $edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&amp;cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
  395. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
  396. //$msg = Display::tag('h3', $weight.' - '.$min_certification);
  397. $msg = $weight.' - '.$min_certification.$edit_icon;
  398. //@todo show description
  399. $description = (($catobj->get_description() == "" || is_null($catobj->get_description())) ? '' : '<strong>'.get_lang('GradebookDescriptionLog').'</strong>'.': '.$catobj->get_description());
  400. echo Display::return_message($msg, 'normal', false);
  401. if (!empty($description)) {
  402. echo Display::div($description, array());
  403. }
  404. }
  405. }
  406. /**
  407. * @param Category $catobj
  408. * @param $is_course_admin
  409. * @param $is_platform_admin
  410. * @param $simple_search_form
  411. * @param bool $show_add_qualification
  412. * @param bool $show_add_link
  413. */
  414. public function display_reduce_header_gradebook(
  415. $catobj,
  416. $is_course_admin,
  417. $is_platform_admin,
  418. $simple_search_form,
  419. $show_add_qualification = true,
  420. $show_add_link = true
  421. ) {
  422. //student
  423. if (!$is_course_admin) {
  424. $user = api_get_user_info(api_get_user_id());
  425. $catcourse = Category::load($catobj->get_id());
  426. $scoredisplay = ScoreDisplay::instance();
  427. $scorecourse = $catcourse[0]->calc_score(api_get_user_id());
  428. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  429. $cattotal = Category::load(0);
  430. $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
  431. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  432. $scoreinfo = get_lang('StatsStudent').' :<b> '.$user['complete_name'].'</b><br />';
  433. if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search'])))
  434. $scoreinfo .= '<br />'.get_lang('TotalForThisCategory').' : <b>'.$scorecourse_display.'</b>';
  435. $scoreinfo .= '<br />'.get_lang('Total').' : <b>'.$scoretotal_display.'</b>';
  436. Display::addFlash(Display::return_message($scoreinfo, 'normal', false));
  437. }
  438. // show navigation tree and buttons?
  439. $header = '<div class="actions">';
  440. if ($is_course_admin) {
  441. $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>';
  442. $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>';
  443. } elseif (!(isset($_GET['studentoverview']))) {
  444. $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>';
  445. } else {
  446. $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>';
  447. }
  448. $header .= '</div>';
  449. echo $header;
  450. }
  451. /**
  452. * @param $userId
  453. * @param $categoryId
  454. * @return string
  455. */
  456. public static function display_header_user($userId, $categoryId)
  457. {
  458. $user = api_get_user_info($userId);
  459. if (empty($user)) {
  460. return '';
  461. }
  462. $catcourse = Category::load($categoryId);
  463. $scoredisplay = ScoreDisplay::instance();
  464. // generating the total score for a course
  465. $allevals = $catcourse[0]->get_evaluations($userId, true, api_get_course_id());
  466. $alllinks = $catcourse[0]->get_links($userId, true, api_get_course_id());
  467. $evals_links = array_merge($allevals, $alllinks);
  468. $item_value = 0;
  469. $item_total = 0;
  470. for ($count = 0; $count < count($evals_links); $count++) {
  471. $item = $evals_links[$count];
  472. $score = $item->calc_score($userId);
  473. $my_score_denom = ($score[1] == 0) ? 1 : $score[1];
  474. $item_value += $score[0] / $my_score_denom * $item->get_weight();
  475. $item_total += $item->get_weight();
  476. }
  477. $item_value = api_number_format($item_value, 2);
  478. $total_score = array($item_value, $item_total);
  479. $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
  480. $info = '<div class="row"><div class="col-md-3">';
  481. $info .= '<div class="thumbnail"><img src="'.$user['avatar'].'" /></div>';
  482. $info .= '</div>';
  483. $info .= '<div class="col-md-6">';
  484. $info .= get_lang('Name').' : <a target="_blank" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userId.'"> '.
  485. $user['complete_name'].'</a><br />';
  486. if (api_get_setting('show_email_addresses') == 'true') {
  487. $info .= get_lang('Email').' : <a href="mailto:'.$user['email'].'">'.$user['email'].'</a><br />';
  488. }
  489. $info .= get_lang('TotalUser').' : <b>'.$scorecourse_display.'</b>';
  490. $info .= '</div>';
  491. $info .= '</div>';
  492. echo $info;
  493. }
  494. }