create.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /* For license terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../../main/inc/global.inc.php';
  5. api_protect_admin_script();
  6. $plugin = ImsLtiPlugin::create();
  7. $form = new FormValidator('ism_lti_create_tool');
  8. $form->addText('name', get_lang('Name'));
  9. $form->addText('base_url', get_lang('BaseUrl'));
  10. $form->addText('consumer_key', $plugin->get_lang('ConsumerKey'));
  11. $form->addText('shared_secret', $plugin->get_lang('SharedSecret'));
  12. $form->addTextarea('custom_params', $plugin->get_lang('CustomParams'));
  13. $form->addButtonCreate($plugin->get_lang('AddExternalTool'));
  14. if ($form->validate()) {
  15. $formValues = $form->exportValues();
  16. $externalTool = new ImsLtiTool();
  17. $externalTool
  18. ->setName($formValues['name'])
  19. ->setDescription($formValues['description'])
  20. ->setLaunchUrl($formValues['base_url'])
  21. ->setConsumerKey($formValues['consumer_key'])
  22. ->setSharedSecret($formValues['shared_secret'])
  23. ->setCustomParams($formValues['custom_params'])
  24. ->save();
  25. Display::addFlash(
  26. Display::return_message($plugin->get_lang('ToolAdded'), 'success')
  27. );
  28. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/list.php');
  29. exit;
  30. }
  31. $template = new Template($plugin->get_lang('AddExternalTool'));
  32. $template->assign('form', $form->returnForm());
  33. $content = $template->fetch('ims_lti/view/add.tpl');
  34. $template->assign('header', $plugin->get_title());
  35. $template->assign('content', $content);
  36. $template->display_one_col_template();