skill_create.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Create skill form.
  5. *
  6. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. *
  8. * @package chamilo.admin
  9. */
  10. $cidReset = true;
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. Skill::isAllowed();
  15. $interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')];
  16. $interbreadcrumb[] = ['url' => 'skill_list.php', 'name' => get_lang('ManageSkills')];
  17. /* Process data */
  18. $skillParentId = isset($_GET['parent']) ? intval($_GET['parent']) : 0;
  19. $formDefaultValues = [];
  20. $objSkill = new Skill();
  21. if ($skillParentId > 0) {
  22. $skillParentInfo = $objSkill->getSkillInfo($skillParentId);
  23. $formDefaultValues = [
  24. 'parent_id' => $skillParentInfo['id'],
  25. 'gradebook_id' => [],
  26. ];
  27. foreach ($skillParentInfo['gradebooks'] as $gradebook) {
  28. $formDefaultValues['gradebook_id'][] = intval($gradebook['id']);
  29. }
  30. }
  31. /* Form */
  32. $createForm = new FormValidator('skill_create');
  33. $createForm->addHeader(get_lang('CreateSkill'));
  34. $returnParams = $objSkill->setForm($createForm, []);
  35. $jquery_ready_content = $returnParams['jquery_ready_content'];
  36. // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
  37. if (!empty($jquery_ready_content)) {
  38. $htmlHeadXtra[] = '<script>
  39. $(function () {
  40. '.$jquery_ready_content.'
  41. });
  42. </script>';
  43. }
  44. $createForm->setDefaults($formDefaultValues);
  45. if ($createForm->validate()) {
  46. $skillValues = $createForm->getSubmitValues();
  47. $created = $objSkill->add($skillValues);
  48. $skillValues['item_id'] = $created;
  49. $extraFieldValue = new ExtraFieldValue('skill');
  50. $extraFieldValue->saveFieldValues($skillValues);
  51. if ($created) {
  52. $url = api_get_path(WEB_CODE_PATH).'admin/skill_edit.php?id='.$created;
  53. $link = Display::url($skillValues['name'], $url);
  54. Display::addFlash(
  55. Display::return_message(get_lang('TheSkillHasBeenCreated').': '.$link, 'success', false)
  56. );
  57. } else {
  58. Display::addFlash(
  59. Display::return_message(get_lang('CannotCreateSkill'), 'error')
  60. );
  61. }
  62. header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php');
  63. exit;
  64. }
  65. $toolbar = $objSkill->getToolbar();
  66. $tpl = new Template(get_lang('CreateSkill'));
  67. $tpl->assign('content', $toolbar.$createForm->returnForm());
  68. $tpl->display_one_col_template();