skills_gradebook.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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::isAllow();
  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('SkillsAndGradebooks');
  16. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  17. if ($action == 'add_skill') {
  18. $interbreadcrumb[] = array('url' => 'skills_gradebook.php', 'name' => get_lang('SkillsAndGradebooks'));
  19. $tool_name = get_lang('Add');
  20. }
  21. Display::display_header($tool_name);
  22. //jqgrid will use this URL to do the selects
  23. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_gradebooks';
  24. //The order is important you need to check the the $column variable in the model.ajax.php file
  25. $columns = array(
  26. get_lang('Name'),
  27. get_lang('CertificatesFiles'),
  28. get_lang('Skills'),
  29. get_lang('Actions')
  30. );
  31. //Column config
  32. $column_model = array(
  33. array(
  34. 'name' => 'name',
  35. 'index' => 'name',
  36. 'width' => '150',
  37. 'align' => 'left'
  38. ),
  39. array(
  40. 'name' => 'certificate',
  41. 'index' => 'certificate',
  42. 'width' => '25',
  43. 'align' => 'left',
  44. 'sortable' => 'false'
  45. ),
  46. array(
  47. 'name' => 'skills',
  48. 'index' => 'skills',
  49. 'width' => '300',
  50. 'align' => 'left',
  51. 'sortable' => 'false'
  52. ),
  53. array(
  54. 'name' => 'actions',
  55. 'index' => 'actions',
  56. 'width' => '30',
  57. 'align' => 'left',
  58. 'formatter' => 'action_formatter',
  59. 'sortable' => 'false'
  60. )
  61. );
  62. //Autowidth
  63. $extra_params['autowidth'] = 'true';
  64. //height auto
  65. $extra_params['height'] = 'auto';
  66. //With this function we can add actions to the jgrid (edit, delete, etc)
  67. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  68. //certificates
  69. if (rowObject[4] == 1) {
  70. return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.Display::return_icon('add.png', get_lang('AddSkill'), '', ICON_SIZE_SMALL).'</a>'.'\';
  71. } else {
  72. return \''.Display::return_icon('add_na.png', get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'), '', ICON_SIZE_SMALL).''.'\';
  73. }
  74. }';
  75. ?>
  76. <script>
  77. $(function() {
  78. <?php
  79. // grid definition see the $career->display() function
  80. echo Display::grid_js(
  81. 'gradebooks',
  82. $url,
  83. $columns,
  84. $column_model,
  85. $extra_params,
  86. array(),
  87. $action_links,
  88. true
  89. );
  90. ?>
  91. });
  92. </script>
  93. <?php
  94. $gradebook = new Gradebook();
  95. switch ($action) {
  96. case 'display':
  97. $gradebook->display();
  98. break;
  99. case 'add_skill':
  100. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  101. $gradebook_info = $gradebook->get($id);
  102. $url = api_get_self().'?action='.$action.'&id='.$id;
  103. $form = $gradebook->show_skill_form($id, $url, $gradebook_info['name']);
  104. if ($form->validate()) {
  105. $values = $form->exportValues();
  106. $res = $gradebook->update_skills_to_gradebook($values['id'], $values['skill']);
  107. if ($res) {
  108. echo Display::return_message(get_lang('ItemAdded'), 'confirm');
  109. }
  110. }
  111. $form->display();
  112. break;
  113. }
  114. Display::display_footer();