add.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /* For license terms, see /license.txt */
  3. require_once __DIR__.'/../../main/inc/global.inc.php';
  4. api_protect_course_script();
  5. api_protect_teacher_script();
  6. $plugin = ImsLtiPlugin::create();
  7. $em = Database::getManager();
  8. $course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
  9. $tools = ImsLtiTool::fetchAll();
  10. $types = [
  11. '0' => get_lang('None')
  12. ];
  13. foreach ($tools as $tool) {
  14. $types[$tool['id']] = $tool['name'];
  15. }
  16. $form = new FormValidator('ims_lti_add_tool');
  17. $form->addText('tool_name', $plugin->get_lang('ToolName'));
  18. $form->addSelect('type', $plugin->get_lang('Type'), $types);
  19. $form->addRule('type', get_lang('Required'), 'required');
  20. $form->addHtml('<div id="show_advanced_options">');
  21. $form->addElement('url', 'url', $plugin->get_lang('LaunchUrl'));
  22. $form->addText('consumer_key', $plugin->get_lang('ConsumerKey'), false);
  23. $form->addText('shared_secret', $plugin->get_lang('SharedSecret'), false);
  24. $form->addTextarea('custom_params', $plugin->get_lang('CustomParams'));
  25. $form->addHtml('</div>');
  26. $form->addButtonCreate($plugin->get_lang('AddExternalTool'));
  27. if ($form->validate()) {
  28. $formValues = $form->getSubmitValues();
  29. if (!empty($formValues['type'])) {
  30. $tool = ImsLtiTool::fetch($formValues['type']);
  31. if (!$tool) {
  32. Display::addFlash(
  33. Display::return_message($plugin->get_lang('NoTool'))
  34. );
  35. // redirect to course
  36. exit;
  37. }
  38. $plugin->addCourseTool($course, $tool);
  39. }
  40. }
  41. $template = new Template($plugin->get_lang('AddExternalTool'));
  42. $template->assign('form', $form->returnForm());
  43. $content = $template->fetch('ims_lti/view/add.tpl');
  44. $template->assign('content', $content);
  45. $template->display_one_col_template();