skill_edit.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Skill edit 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. $skillId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  20. $objSkill = new Skill();
  21. $objGradebook = new Gradebook();
  22. $skillInfo = $objSkill->get_skill_info($skillId);
  23. $allSkills = $objSkill->get_all();
  24. $allGradebooks = $objGradebook->find('all');
  25. $skillDefaultInfo = [
  26. 'id' => $skillInfo['id'],
  27. 'name' => $skillInfo['name'],
  28. 'short_code' => $skillInfo['short_code'],
  29. 'description' => $skillInfo['description'],
  30. 'parent_id' => $skillInfo['extra']['parent_id'],
  31. 'gradebook_id' => []
  32. ];
  33. foreach ($skillInfo['gradebooks'] as $gradebook) {
  34. $skillDefaultInfo['gradebook_id'][] = $gradebook['id'];
  35. }
  36. $skillList = [0 => get_lang('None')];
  37. $gradebookList = [];
  38. foreach ($allSkills as $skill) {
  39. if ($skill['id'] == $skillInfo['id']) {
  40. continue;
  41. }
  42. $skillList[$skill['id']] = $skill['name'];
  43. }
  44. foreach ($allGradebooks as $gradebook) {
  45. $gradebookList[$gradebook['id']] = $gradebook['name'];
  46. }
  47. /* Form */
  48. $editForm = new FormValidator('skill_edit');
  49. $editForm->addHeader(get_lang('SkillEdit'));
  50. $editForm->addText('name', get_lang('Name'), true, ['id' => 'name']);
  51. $editForm->addText('short_code', get_lang('ShortCode'), false, ['id' => 'short_code']);
  52. $editForm->addSelect('parent_id', get_lang('Parent'), $skillList, ['id' => 'parent_id']);
  53. $editForm->addSelect(
  54. 'gradebook_id',
  55. [get_lang('Gradebook'), get_lang('WithCertificate')],
  56. $gradebookList,
  57. ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
  58. );
  59. $editForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
  60. $editForm->addButtonSave(get_lang('Save'));
  61. $editForm->addHidden('id', null);
  62. $editForm->setDefaults($skillDefaultInfo);
  63. if ($editForm->validate()) {
  64. $updated = $objSkill->edit($editForm->getSubmitValues());
  65. if ($updated) {
  66. Session::write(
  67. 'message',
  68. Display::return_message(get_lang('TheSkillHasBeenUpdated'), 'success')
  69. );
  70. } else {
  71. Session::write(
  72. 'message',
  73. Display::return_message(get_lang('CannotUpdateSkill'), 'error')
  74. );
  75. }
  76. Header::location(api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php');
  77. }
  78. /* view */
  79. $tpl = new Template(get_lang('SkillEdit'));
  80. $tpl->assign('content', $editForm->returnForm());
  81. $tpl->display_one_col_template();