edit.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. $toolId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  7. if (empty($toolId)) {
  8. api_not_allowed(true);
  9. }
  10. $plugin = ImsLtiPlugin::create();
  11. $tool = ImsLtiTool::fetch($toolId);
  12. if (empty($tool)) {
  13. Display::addFlash(
  14. Display::return_message($plugin->get_lang('NoTool'), 'error')
  15. );
  16. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/list.php');
  17. exit;
  18. }
  19. $form = new FormValidator('ims_lti_edit_tool');
  20. $form->addText('name', get_lang('Name'));
  21. $form->addTextarea('description', get_lang('Description'));
  22. $form->addText('url', get_lang('Url'));
  23. $form->addText('consumer_key', $plugin->get_lang('ConsumerKey'));
  24. $form->addText('shared_secret', $plugin->get_lang('SharedSecret'));
  25. $form->addTextarea('custom_params', $plugin->get_lang('CustomParams'));
  26. $form->addButtonCreate($plugin->get_lang('AddExternalTool'));
  27. $form->addHidden('id', $tool->getId());
  28. $form->setDefaults([
  29. 'name' => $tool->getName(),
  30. 'description' => $tool->getDescription(),
  31. 'url' => $tool->getLaunchUrl(),
  32. 'consumer_key' => $tool->getConsumerKey(),
  33. 'shared_secret' => $tool->getSharedSecret(),
  34. 'custom_params' => $tool->getCustomParams()
  35. ]);
  36. if ($form->validate()) {
  37. $formValues = $form->exportValues();
  38. $tool
  39. ->setName($formValues['name'])
  40. ->setDescription($formValues['description'])
  41. ->setLaunchUrl($formValues['url'])
  42. ->setConsumerKey($formValues['consumer_key'])
  43. ->setSharedSecret($formValues['shared_secret'])
  44. ->setCustomParams($formValues['custom_params'])
  45. ->save();
  46. Display::addFlash(
  47. Display::return_message($plugin->get_lang('ToolEdited'), 'success')
  48. );
  49. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/list.php');
  50. exit;
  51. }
  52. $template = new Template($plugin->get_lang('EditExternalTool'));
  53. $template->assign('form', $form->returnForm());
  54. $content = $template->fetch('ims_lti/view/add.tpl');
  55. $template->assign('header', $plugin->get_title());
  56. $template->assign('content', $content);
  57. $template->display_one_col_template();