* @package chamilo.admin */ $cidReset = true; //require_once '../inc/global.inc.php'; $this_section = SECTION_PLATFORM_ADMIN; api_protect_admin_script(); if (api_get_setting('skill.allow_skills_tool') != 'true') { api_not_allowed(); } $interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration') , "name" => get_lang('PlatformAdmin')); $interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills')); $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateSkill')); /* Process data */ $skillParentId = isset($_GET['parent']) ? intval($_GET['parent']) : 0; $formDefaultValues = []; $objSkill = new Skill(); $objGradebook = new Gradebook(); if ($skillParentId > 0) { $skillParentInfo = $objSkill->get_skill_info($skillParentId); $formDefaultValues = [ 'parent_id' => $skillParentInfo['id'], 'gradebook_id' => [] ]; foreach ($skillParentInfo['gradebooks'] as $gradebook) { $formDefaultValues['gradebook_id'][] = intval($gradebook['id']); } } $allSkills = $objSkill->get_all(); $allGradebooks = $objGradebook->find('all'); $isAlreadyRootSkill = false; foreach ($allSkills as $checkedSkill) { if (intval($checkedSkill['parent_id']) > 0) { $isAlreadyRootSkill = true; break; } } $skillList = $isAlreadyRootSkill ? [] : [0 => get_lang('None')]; $gradebookList = []; foreach ($allSkills as $skill) { $skillList[$skill['id']] = $skill['name']; } foreach ($allGradebooks as $gradebook) { $gradebookList[$gradebook['id']] = $gradebook['name']; } /* Form */ $createForm = new FormValidator('skill_create'); $createForm->addHeader(get_lang('CreateSkill')); $createForm->addText('name', get_lang('Name'), true, ['id' => 'name']); $createForm->addText('short_code', get_lang('ShortCode'), false, ['id' => 'short_code']); $createForm->addSelect('parent_id', get_lang('Parent'), $skillList, ['id' => 'parent_id']); $createForm->addSelect( 'gradebook_id', [get_lang('Gradebook'), get_lang('WithCertificate')], $gradebookList, ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10] ); $createForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]); $extraField = new ExtraField('skill'); $returnParams = $extraField->addElements($createForm); $jquery_ready_content = $returnParams['jquery_ready_content']; // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function if (!empty($jquery_ready_content)) { $htmlHeadXtra[] = ''; } $createForm->addButtonSave(get_lang('Save')); $createForm->addHidden('id', null); $createForm->setDefaults($formDefaultValues); if ($createForm->validate()) { $skillValues = $createForm->getSubmitValues(); $created = $objSkill->add($skillValues); $skillValues['item_id'] = $created; $extraFieldValue = new ExtraFieldValue('skill'); $extraFieldValue->saveFieldValues($skillValues); if ($created) { Display::return_message(get_lang('TheSkillHasBeenCreated'), 'success'); } else { Display::return_message(get_lang('CannotCreateSkill'), 'error'); } header('Location: '.api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php'); exit; } //$tpl = new Template(get_lang('CreateSkill')); echo $createForm->returnForm();