skill_edit.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. use Chamilo\CoreBundle\Framework\Container;
  5. /**
  6. * Skill edit form
  7. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  8. * @package chamilo.admin
  9. */
  10. $cidReset = true;
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. if (api_get_setting('skill.allow_skills_tool') != 'true') {
  14. api_not_allowed();
  15. }
  16. $interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration') , "name" => get_lang('PlatformAdmin'));
  17. $interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills'));
  18. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('SkillEdit'));
  19. /* Process data */
  20. $skillId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  21. $objSkill = new Skill();
  22. $objGradebook = new Gradebook();
  23. $skillInfo = $objSkill->get_skill_info($skillId);
  24. $allSkills = $objSkill->get_all();
  25. $allGradebooks = $objGradebook->find('all');
  26. $skillDefaultInfo = [
  27. 'id' => $skillInfo['id'],
  28. 'name' => $skillInfo['name'],
  29. 'short_code' => $skillInfo['short_code'],
  30. 'description' => $skillInfo['description'],
  31. 'parent_id' => $skillInfo['extra']['parent_id'],
  32. 'gradebook_id' => []
  33. ];
  34. foreach ($skillInfo['gradebooks'] as $gradebook) {
  35. $skillDefaultInfo['gradebook_id'][] = $gradebook['id'];
  36. }
  37. $skillList = [0 => get_lang('None')];
  38. $gradebookList = [];
  39. foreach ($allSkills as $skill) {
  40. if ($skill['id'] == $skillInfo['id']) {
  41. continue;
  42. }
  43. $skillList[$skill['id']] = $skill['name'];
  44. }
  45. foreach ($allGradebooks as $gradebook) {
  46. $gradebookList[$gradebook['id']] = $gradebook['name'];
  47. }
  48. /* Form */
  49. $editForm = new FormValidator('skill_edit');
  50. $editForm->addHeader(get_lang('SkillEdit'));
  51. $editForm->addText('name', get_lang('Name'), true, ['id' => 'name']);
  52. $editForm->addText('short_code', get_lang('ShortCode'), false, ['id' => 'short_code']);
  53. $editForm->addSelect('parent_id', get_lang('Parent'), $skillList, ['id' => 'parent_id']);
  54. $editForm->addSelect(
  55. 'gradebook_id',
  56. [get_lang('Gradebook'), get_lang('WithCertificate')],
  57. $gradebookList,
  58. ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
  59. );
  60. $editForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
  61. $extraField = new ExtraField('skill');
  62. $returnParams = $extraField->addElements($editForm, $skillId);
  63. $jquery_ready_content = $returnParams['jquery_ready_content'];
  64. // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
  65. if (!empty($jquery_ready_content)) {
  66. $htmlHeadXtra[] = '<script>
  67. $(document).ready(function(){
  68. ' . $jquery_ready_content . '
  69. });
  70. </script>';
  71. }
  72. $editForm->addButtonSave(get_lang('Save'));
  73. $editForm->addHidden('id', null);
  74. $editForm->setDefaults($skillDefaultInfo);
  75. if ($editForm->validate()) {
  76. $skillValues = $editForm->getSubmitValues();
  77. $updated = $objSkill->edit($skillValues);
  78. $extraFieldValue = new ExtraFieldValue('skill');
  79. $extraFieldValue->saveFieldValues($skillValues);
  80. if ($updated) {
  81. Display::return_message(get_lang('TheSkillHasBeenUpdated'), 'success');
  82. } else {
  83. Display::return_message(get_lang('CannotUpdateSkill'), 'error');
  84. }
  85. header('Location: '.api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php');
  86. exit;
  87. }
  88. echo $editForm->returnForm();