skills_gradebook.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. if (api_get_setting('skill.allow_skills_tool') != 'true') {
  11. api_not_allowed();
  12. }
  13. //Adds the JS needed to use the jqgrid
  14. $htmlHeadXtra[] = api_get_jqgrid_js();
  15. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'display';
  16. // setting breadcrumbs
  17. $tool_name = get_lang('SkillsAndGradebooks');
  18. $interbreadcrumb[]=array('url' => Container::getRouter()->generate('administration'),'name' => get_lang('PlatformAdmin'));
  19. if ($action == 'add_skill') {
  20. $interbreadcrumb[]=array('url' => 'skills_gradebook.php','name' => get_lang('SkillsAndGradebooks'));
  21. $tool_name = get_lang('Add');
  22. }
  23. Display::display_header($tool_name);
  24. //jqgrid will use this URL to do the selects
  25. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_gradebooks';
  26. //The order is important you need to check the the $column variable in the model.ajax.php file
  27. $columns = array(
  28. get_lang('Name'),
  29. get_lang('CertificatesFiles'),
  30. get_lang('Skills'),
  31. get_lang('Actions')
  32. );
  33. //Column config
  34. $column_model = array(
  35. array(
  36. 'name' => 'name',
  37. 'index' => 'name',
  38. 'width' => '150',
  39. 'align' => 'left'
  40. ),
  41. array(
  42. 'name' => 'certificate',
  43. 'index' => 'certificate',
  44. 'width' => '25',
  45. 'align' => 'left',
  46. 'sortable' => 'false'
  47. ),
  48. array(
  49. 'name' => 'skills',
  50. 'index' => 'skills',
  51. 'width' => '300',
  52. 'align' => 'left',
  53. 'sortable' => 'false'
  54. ),
  55. array(
  56. 'name' => 'actions',
  57. 'index' => 'actions',
  58. 'width' => '30',
  59. 'align' => 'left',
  60. 'formatter' => 'action_formatter',
  61. 'sortable' => 'false'
  62. )
  63. );
  64. //Autowidth
  65. $extra_params['autowidth'] = 'true';
  66. //height auto
  67. $extra_params['height'] = 'auto';
  68. //With this function we can add actions to the jgrid (edit, delete, etc)
  69. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  70. //certificates
  71. if (rowObject[4] == 1) {
  72. return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.Display::return_icon('add.png', get_lang('AddSkill'),'',ICON_SIZE_SMALL).'</a>'.'\';
  73. } else {
  74. return \''.Display::return_icon('add_na.png', get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'),'',ICON_SIZE_SMALL).''.'\';
  75. }
  76. }';
  77. ?>
  78. <script>
  79. $(function() {
  80. <?php
  81. // grid definition see the $career->display() function
  82. echo Display::grid_js('gradebooks', $url, $columns, $column_model, $extra_params, array(), $action_links,true);
  83. ?>
  84. });
  85. </script>
  86. <?php
  87. $gradebook = new Gradebook();
  88. switch($action) {
  89. case 'display':
  90. $gradebook->display();
  91. break;
  92. case 'add_skill':
  93. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  94. $gradebook_info = $gradebook->get($id);
  95. $url = api_get_self().'?action='.$action.'&id='.$id;
  96. $form = $gradebook->show_skill_form($id, $url, $gradebook_info['name']);
  97. if ($form->validate()) {
  98. $values = $form->exportValues();
  99. $res = $gradebook->update_skills_to_gradebook($values['id'], $values['skill']);
  100. if ($res) {
  101. Display::display_confirmation_message(get_lang('ItemAdded'));
  102. }
  103. }
  104. $form->display();
  105. //echo Display::tag('h2',$gradebook_info['name']);
  106. break;
  107. }
  108. Display::display_footer();