start.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /* For license terms, see /license.txt */
  3. require_once __DIR__.'/config.php';
  4. // Course legal
  5. $enabled = api_get_plugin_setting('courselegal', 'tool_enable');
  6. if ($enabled != 'true') {
  7. api_not_allowed(true);
  8. }
  9. if (!api_is_allowed_to_edit()) {
  10. api_not_allowed(true);
  11. }
  12. $legal = CourseLegalPlugin::create();
  13. $url = api_get_self().'?'.api_get_cidreq();
  14. $courseId = api_get_course_int_id();
  15. $sessionId = api_get_session_id();
  16. $form = new FormValidator('plugin', 'post', $url);
  17. $form->addElement('header', $legal->get_lang('CourseLegal'));
  18. $form->addElement('hidden', 'session_id', $sessionId);
  19. $form->addElement('hidden', 'c_id', $courseId);
  20. $form->addHtmlEditor(
  21. 'content',
  22. get_lang('Text'),
  23. true,
  24. false,
  25. ['ToolbarSet' => 'TermsAndConditions']
  26. );
  27. $form->addElement('file', 'uploaded_file', get_lang('File'));
  28. $file = $legal->getCurrentFile($courseId, $sessionId);
  29. if (!empty($file)) {
  30. $form->addElement('label', get_lang('File'), $file);
  31. }
  32. $form->addElement('checkbox', 'delete_file', null, $legal->get_lang('DeleteFile'));
  33. $form->addElement('checkbox', 'remove_previous_agreements', null, $legal->get_lang('RemoveAllUserAgreements'));
  34. $form->addElement('radio', 'warn_users_by_email', null, $legal->get_lang('NoSendWarning'), 1);
  35. $form->addElement('radio', 'warn_users_by_email', $legal->get_lang('WarnAllUsersByEmail'), $legal->get_lang('SendOnlyWarning'), 2);
  36. $form->addElement('radio', 'warn_users_by_email', null, $legal->get_lang('SendAgreementFile'), 3);
  37. $form->addButtonSave(get_lang('Save'));
  38. $defaults = $legal->getData($courseId, $sessionId);
  39. $defaults['warn_users_by_email'] = 1;
  40. $form->setDefaults($defaults);
  41. if ($form->validate()) {
  42. $values = $form->getSubmitValues();
  43. $file = isset($_FILES['uploaded_file']) ? $_FILES['uploaded_file'] : [];
  44. $deleteFile = isset($values['delete_file']) ? $values['delete_file'] : false;
  45. $legal->save($values, $file, $deleteFile);
  46. header('Location: '.$url);
  47. exit;
  48. }
  49. Display::display_header($legal->get_lang('CourseLegal'));
  50. $url = api_get_path(WEB_PLUGIN_PATH).'courselegal/user_list.php?'.api_get_cidreq();
  51. $link = Display::url(Display::return_icon('user.png', get_lang('User list')), $url);
  52. echo '<div class="actions">'.$link.'</div>';
  53. $form->display();
  54. Display::display_footer();