skills_gradebook.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. Skill::isAllowed();
  11. //Adds the JS needed to use the jqgrid
  12. $htmlHeadXtra[] = api_get_jqgrid_js();
  13. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'display';
  14. // setting breadcrumbs
  15. $tool_name = get_lang('Skills and assessments');
  16. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  17. if ($action == 'add_skill') {
  18. $interbreadcrumb[] = ['url' => 'skills_gradebook.php', 'name' => get_lang('Skills and assessments')];
  19. $tool_name = get_lang('Add');
  20. }
  21. $gradebook = new Gradebook();
  22. switch ($action) {
  23. case 'display':
  24. $content = $gradebook->returnGrid();
  25. break;
  26. case 'add_skill':
  27. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  28. $gradebook_info = $gradebook->get($id);
  29. $url = api_get_self().'?action='.$action.'&id='.$id;
  30. $form = $gradebook->show_skill_form($id, $url, $gradebook_info['name']);
  31. if ($form->validate()) {
  32. $values = $form->exportValues();
  33. $gradebook->updateSkillsToGradeBook($values['id'], $values['skill']);
  34. Display::addFlash(Display::return_message(get_lang('Item added'), 'confirm'));
  35. header('Location: '.api_get_self());
  36. exit;
  37. }
  38. $content = $form->returnForm();
  39. break;
  40. }
  41. Display::display_header($tool_name);
  42. //jqgrid will use this URL to do the selects
  43. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_gradebooks';
  44. //The order is important you need to check the the $column variable in the model.ajax.php file
  45. $columns = [
  46. get_lang('Name'),
  47. get_lang('Certificates'),
  48. get_lang('Skills'),
  49. get_lang('Detail'),
  50. ];
  51. //Column config
  52. $column_model = [
  53. [
  54. 'name' => 'name',
  55. 'index' => 'name',
  56. 'width' => '150',
  57. 'align' => 'left',
  58. ],
  59. [
  60. 'name' => 'certificate',
  61. 'index' => 'certificate',
  62. 'width' => '25',
  63. 'align' => 'left',
  64. 'sortable' => 'false',
  65. ],
  66. [
  67. 'name' => 'skills',
  68. 'index' => 'skills',
  69. 'width' => '300',
  70. 'align' => 'left',
  71. 'sortable' => 'false',
  72. ],
  73. [
  74. 'name' => 'actions',
  75. 'index' => 'actions',
  76. 'width' => '30',
  77. 'align' => 'left',
  78. 'formatter' => 'action_formatter',
  79. 'sortable' => 'false',
  80. ],
  81. ];
  82. //Autowidth
  83. $extra_params['autowidth'] = 'true';
  84. //height auto
  85. $extra_params['height'] = 'auto';
  86. $iconAdd = Display::return_icon('add.png', addslashes(get_lang('Add skill')));
  87. $iconAddNa = Display::return_icon(
  88. 'add_na.png',
  89. addslashes(get_lang('Your gradebook first needs a certificate in order to be linked to a skill'))
  90. );
  91. //With this function we can add actions to the jgrid (edit, delete, etc)
  92. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  93. //certificates
  94. if (rowObject[4] == 1) {
  95. return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.$iconAdd.'</a>'.'\';
  96. } else {
  97. return \''.$iconAddNa.'\';
  98. }
  99. }';
  100. ?>
  101. <script>
  102. $(function() {
  103. <?php
  104. // grid definition see the $career->display() function
  105. echo Display::grid_js(
  106. 'gradebooks',
  107. $url,
  108. $columns,
  109. $column_model,
  110. $extra_params,
  111. [],
  112. $action_links,
  113. true
  114. );
  115. ?>
  116. });
  117. </script>
  118. <?php
  119. echo $content;
  120. Display::display_footer();