skill_create.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Create skill form
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.admin
  7. */
  8. use ChamiloSession as Session;
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. if (api_get_setting('allow_skills_tool') != 'true') {
  14. api_not_allowed();
  15. }
  16. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  17. $interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills'));
  18. /* Process data */
  19. $skillParentId = isset($_GET['parent']) ? intval($_GET['parent']) : 0;
  20. $formDefaultValues = [];
  21. $objSkill = new Skill();
  22. $objGradebook = new Gradebook();
  23. if ($skillParentId > 0) {
  24. $skillParentInfo = $objSkill->get_skill_info($skillParentId);
  25. $formDefaultValues = [
  26. 'parent_id' => $skillParentInfo['id'],
  27. 'gradebook_id' => []
  28. ];
  29. foreach ($skillParentInfo['gradebooks'] as $gradebook) {
  30. $formDefaultValues['gradebook_id'][] = intval($gradebook['id']);
  31. }
  32. }
  33. $allSkills = $objSkill->get_all();
  34. $allGradebooks = $objGradebook->find('all');
  35. $skillList = [0 => get_lang('None')];
  36. $gradebookList = [];
  37. foreach ($allSkills as $skill) {
  38. $skillList[$skill['id']] = $skill['name'];
  39. }
  40. foreach ($allGradebooks as $gradebook) {
  41. $gradebookList[$gradebook['id']] = $gradebook['name'];
  42. }
  43. /* Form */
  44. $createForm = new FormValidator('skill_create');
  45. $createForm->addHeader(get_lang('CreateSkill'));
  46. $createForm->addText('name', get_lang('Name'), true, ['id' => 'name']);
  47. $createForm->addText('short_code', get_lang('ShortCode'), false, ['id' => 'short_code']);
  48. $createForm->addSelect('parent_id', get_lang('Parent'), $skillList, ['id' => 'parent_id']);
  49. $createForm->addSelect(
  50. 'gradebook_id',
  51. [get_lang('Gradebook'), get_lang('WithCertificate')],
  52. $gradebookList,
  53. ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
  54. );
  55. $createForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
  56. $createForm->addButtonSave(get_lang('Save'));
  57. $createForm->addHidden('id', null);
  58. $createForm->setDefaults($formDefaultValues);
  59. if ($createForm->validate()) {
  60. $created = $objSkill->add($createForm->getSubmitValues());
  61. if ($created) {
  62. Session::write(
  63. 'message',
  64. Display::return_message(get_lang('TheSkillHasBeenCreated'), 'success')
  65. );
  66. } else {
  67. Session::write(
  68. 'message',
  69. Display::return_message(get_lang('CannotCreateSkill'), 'error')
  70. );
  71. }
  72. Header::location(api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php');
  73. }
  74. /* view */
  75. $tpl = new Template(get_lang('CreateSkill'));
  76. $tpl->assign('content', $createForm->returnForm());
  77. $tpl->display_one_col_template();