skills_gradebook.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once '../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. if (api_get_setting('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' => 'index.php','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(get_lang('Name'), get_lang('CertificatesFiles'), get_lang('Skills'), get_lang('Actions'));
  28. //Column config
  29. $column_model = array(
  30. array('name'=>'name', 'index'=>'name', 'width'=>'150', 'align'=>'left'),
  31. array('name'=>'certificate', 'index'=>'certificate', 'width'=>'25', 'align'=>'left', 'sortable'=>'false'),
  32. array('name'=>'skills', 'index'=>'skills', 'width'=>'300', 'align'=>'left', 'sortable'=>'false'),
  33. array('name'=>'actions', 'index'=>'actions', 'width'=>'30', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
  34. );
  35. //Autowidth
  36. $extra_params['autowidth'] = 'true';
  37. //height auto
  38. $extra_params['height'] = 'auto';
  39. //With this function we can add actions to the jgrid (edit, delete, etc)
  40. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  41. //certificates
  42. if (rowObject[4] == 1) {
  43. return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.Display::return_icon('add.png', get_lang('AddSkill'),'',ICON_SIZE_SMALL).'</a>'.'\';
  44. } else {
  45. return \''.Display::return_icon('add_na.png', get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'),'',ICON_SIZE_SMALL).''.'\';
  46. }
  47. }';
  48. ?>
  49. <script>
  50. $(function() {
  51. <?php
  52. // grid definition see the $career->display() function
  53. echo Display::grid_js('gradebooks', $url, $columns, $column_model, $extra_params, array(), $action_links,true);
  54. ?>
  55. });
  56. </script>
  57. <?php
  58. $gradebook = new Gradebook();
  59. switch($action) {
  60. case 'display':
  61. $gradebook->display();
  62. break;
  63. case 'add_skill':
  64. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  65. $gradebook_info = $gradebook->get($id);
  66. $url = api_get_self().'?action='.$action.'&id='.$id;
  67. $form = $gradebook->show_skill_form($id, $url, $gradebook_info['name']);
  68. if ($form->validate()) {
  69. $values = $form->exportValues();
  70. $res = $gradebook->update_skills_to_gradebook($values['id'], $values['skill']);
  71. if ($res) {
  72. Display::display_confirmation_message(get_lang('ItemAdded'));
  73. }
  74. }
  75. $form->display();
  76. //echo Display::tag('h2',$gradebook_info['name']);
  77. break;
  78. }
  79. Display::display_footer();