skills_gradebook.php 3.8 KB

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