build(); if ($form->validate()) { $formValues = $form->exportValues(); $externalTool = new ImsLtiTool(); $externalTool ->setName($formValues['name']) ->setDescription( empty($formValues['description']) ? null : $formValues['description'] ) ->setCustomParams( empty($formValues['custom_params']) ? null : $formValues['custom_params'] ) ->setCourse(null) ->setActiveDeepLinking( isset($formValues['deep_linking']) ) ->setPrivacy( isset($formValues['share_name']), isset($formValues['share_email']), isset($formValues['share_picture']) ); if (empty($formValues['consumer_key']) && empty($formValues['shared_secret'])) { try { $launchUrl = $plugin->getLaunchUrlFromCartridge($formValues['launch_url']); } catch (Exception $e) { Display::addFlash( Display::return_message($e->getMessage(), 'error') ); header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; } $externalTool->setLaunchUrl($launchUrl); } else { $externalTool ->setLaunchUrl($formValues['launch_url']) ->setConsumerKey( empty($formValues['consumer_key']) ? null : $formValues['consumer_key'] ) ->setSharedSecret( empty($formValues['shared_secret']) ? null : $formValues['shared_secret'] ); } $em->persist($externalTool); $em->flush(); Display::addFlash( Display::return_message($plugin->get_lang('ToolAdded'), 'success') ); header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; } $form->setDefaultValues(); $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()]; $pageTitle = $plugin->get_lang('AddExternalTool'); $template = new Template($pageTitle); $template->assign('form', $form->returnForm()); $content = $template->fetch('ims_lti/view/add.tpl'); $template->assign('header', $pageTitle); $template->assign('content', $content); $template->display_one_col_template();