skill_edit.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Skill edit 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. $skillId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  19. $objSkill = new Skill();
  20. $objGradebook = new Gradebook();
  21. $skillInfo = $objSkill->getSkillInfo($skillId);
  22. $allGradebooks = $objGradebook->find('all');
  23. $skillDefaultInfo = [
  24. 'id' => $skillInfo['id'],
  25. 'name' => $skillInfo['name'],
  26. 'short_code' => $skillInfo['short_code'],
  27. 'description' => $skillInfo['description'],
  28. 'parent_id' => $skillInfo['extra']['parent_id'],
  29. 'criteria' => $skillInfo['criteria'],
  30. 'gradebook_id' => [],
  31. ];
  32. foreach ($skillInfo['gradebooks'] as $gradebook) {
  33. $skillDefaultInfo['gradebook_id'][] = $gradebook['id'];
  34. }
  35. $gradebookList = [];
  36. foreach ($allGradebooks as $gradebook) {
  37. $gradebookList[$gradebook['id']] = $gradebook['name'];
  38. }
  39. /* Form */
  40. $editForm = new FormValidator('skill_edit');
  41. $editForm->addHeader(get_lang('SkillEdit'));
  42. $returnParams = $objSkill->setForm($editForm, $skillInfo);
  43. $jquery_ready_content = $returnParams['jquery_ready_content'];
  44. // the $jquery_ready_content variable collects all functions that will be load
  45. // in the $(document).ready javascript function
  46. if (!empty($jquery_ready_content)) {
  47. $htmlHeadXtra[] = '<script>
  48. $(document).ready(function(){
  49. '.$jquery_ready_content.'
  50. });
  51. </script>';
  52. }
  53. $editForm->setDefaults($skillDefaultInfo);
  54. if ($editForm->validate()) {
  55. $skillValues = $editForm->getSubmitValues();
  56. $updated = $objSkill->edit($skillValues);
  57. $extraFieldValue = new ExtraFieldValue('skill');
  58. $extraFieldValue->saveFieldValues($skillValues);
  59. if ($updated) {
  60. Display::addFlash(
  61. Display::return_message(
  62. get_lang('TheSkillHasBeenUpdated'),
  63. 'success'
  64. )
  65. );
  66. } else {
  67. Display::addFlash(
  68. Display::return_message(
  69. get_lang('CannotUpdateSkill'),
  70. 'error'
  71. )
  72. );
  73. }
  74. header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php');
  75. exit;
  76. }
  77. $toolbar = $objSkill->getToolBar();
  78. /* view */
  79. $tpl = new Template(get_lang('SkillEdit'));
  80. $tpl->assign('content', $toolbar.$editForm->returnForm());
  81. $tpl->display_one_col_template();