displaygradebook.php 37 KB

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