skill_edit.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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('Administration')];
  16. $interbreadcrumb[] = ['url' => 'skill_list.php', 'name' => get_lang('Manage skills')];
  17. /* Process data */
  18. $skillId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
  19. $objSkill = new Skill();
  20. $objGradebook = new Gradebook();
  21. $skillInfo = $objSkill->getSkillInfo($skillId);
  22. if (empty($skillInfo)) {
  23. api_not_allowed(true);
  24. }
  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. 'criteria' => $skillInfo['criteria'],
  33. 'gradebook_id' => [],
  34. ];
  35. foreach ($skillInfo['gradebooks'] as $gradebook) {
  36. $skillDefaultInfo['gradebook_id'][] = $gradebook['id'];
  37. }
  38. $gradebookList = [];
  39. foreach ($allGradebooks as $gradebook) {
  40. $gradebookList[$gradebook['id']] = $gradebook['name'];
  41. }
  42. /* Form */
  43. $editForm = new FormValidator('skill_edit');
  44. $editForm->addHeader(get_lang('Edit skill'));
  45. $returnParams = $objSkill->setForm($editForm, $skillInfo);
  46. $jquery_ready_content = $returnParams['jquery_ready_content'];
  47. // the $jquery_ready_content variable collects all functions that will be load
  48. // in the $(document).ready javascript function
  49. if (!empty($jquery_ready_content)) {
  50. $htmlHeadXtra[] = '<script>
  51. $(function () {
  52. '.$jquery_ready_content.'
  53. });
  54. </script>';
  55. }
  56. $editForm->setDefaults($skillDefaultInfo);
  57. if ($editForm->validate()) {
  58. $skillValues = $editForm->getSubmitValues();
  59. $updated = $objSkill->edit($skillValues);
  60. $extraFieldValue = new ExtraFieldValue('skill');
  61. $extraFieldValue->saveFieldValues($skillValues);
  62. if ($updated) {
  63. Display::addFlash(
  64. Display::return_message(
  65. get_lang('The skill has been updated'),
  66. 'success'
  67. )
  68. );
  69. } else {
  70. Display::addFlash(
  71. Display::return_message(
  72. get_lang('Cannot update skill'),
  73. 'error'
  74. )
  75. );
  76. }
  77. header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php');
  78. exit;
  79. }
  80. $toolbar = $objSkill->getToolBar();
  81. /* view */
  82. $tpl = new Template(get_lang('Edit skill'));
  83. $tpl->assign('content', $toolbar.$editForm->returnForm());
  84. $tpl->display_one_col_template();