skill_edit.php 3.4 KB

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