start.php 2.3 KB

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