edit.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
  4. $cidReset = true;
  5. require_once __DIR__.'/../../main/inc/global.inc.php';
  6. api_protect_admin_script();
  7. if (!isset($_REQUEST['id'])) {
  8. api_not_allowed(true);
  9. }
  10. $toolId = intval($_REQUEST['id']);
  11. $plugin = ImsLtiPlugin::create();
  12. $em = Database::getManager();
  13. /** @var ImsLtiTool $tool */
  14. $tool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', $toolId);
  15. if (!$tool) {
  16. Display::addFlash(
  17. Display::return_message($plugin->get_lang('NoTool'), 'error')
  18. );
  19. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
  20. exit;
  21. }
  22. $form = new FormValidator('ims_lti_edit_tool');
  23. $form->addText('name', get_lang('Name'));
  24. $form->addText('url', $plugin->get_lang('LaunchUrl'));
  25. $form->addText('consumer_key', $plugin->get_lang('ConsumerKey'));
  26. $form->addText('shared_secret', $plugin->get_lang('SharedSecret'));
  27. $form->addButtonAdvancedSettings('lti_adv');
  28. $form->addHtml('<div id="lti_adv_options" style="display:none;">');
  29. $form->addTextarea('description', get_lang('Description'), ['rows' => 3]);
  30. $form->addTextarea('custom_params', [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]);
  31. $form->addCheckBox('deep_linking', $plugin->get_lang('SupportDeepLinking'), get_lang('Yes'));
  32. $form->addHtml('</div>');
  33. $form->addButtonSave(get_lang('Save'));
  34. $form->addHidden('id', $tool->getId());
  35. $form->setDefaults([
  36. 'name' => $tool->getName(),
  37. 'description' => $tool->getDescription(),
  38. 'url' => $tool->getLaunchUrl(),
  39. 'consumer_key' => $tool->getConsumerKey(),
  40. 'shared_secret' => $tool->getSharedSecret(),
  41. 'custom_params' => $tool->getCustomParams(),
  42. 'deep_linking' => $tool->isActiveDeepLinking(),
  43. ]);
  44. if ($form->validate()) {
  45. $formValues = $form->exportValues();
  46. $tool
  47. ->setName($formValues['name'])
  48. ->setDescription($formValues['description'])
  49. ->setLaunchUrl($formValues['url'])
  50. ->setConsumerKey($formValues['consumer_key'])
  51. ->setSharedSecret($formValues['shared_secret'])
  52. ->setCustomParams($formValues['custom_params']);
  53. $em->persist($tool);
  54. $em->flush();
  55. Display::addFlash(
  56. Display::return_message($plugin->get_lang('ToolUpdated'), 'success')
  57. );
  58. header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php');
  59. exit;
  60. }
  61. $template = new Template($plugin->get_lang('EditExternalTool'));
  62. $template->assign('form', $form->returnForm());
  63. $content = $template->fetch('ims_lti/view/add.tpl');
  64. $template->assign('header', $plugin->get_title());
  65. $template->assign('content', $content);
  66. $template->display_one_col_template();