displaygradebook.php 43 KB

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