/**
  * Add the Turnitin settings form to an add/edit activity page
  *
  * @param object $mform
  * @param object $context
  * @return type
  */
 public function get_form_elements_module($mform, $context, $modulename = "")
 {
     global $DB, $COURSE;
     if (has_capability('plagiarism/turnitin:enable', $context)) {
         // Get Course module id and values.
         $cmid = optional_param('update', null, PARAM_INT);
         // Check Turnitin is configured.
         $config = turnitintooltwo_admin_config();
         if (empty($config->accountid) || empty($config->apiurl) || empty($config->secretkey)) {
             return;
         }
         // Check if plagiarism plugin is enabled for this module if provided.
         if (!empty($modulename)) {
             $moduletiienabled = $this->get_config_settings($modulename);
             if (empty($moduletiienabled)) {
                 return;
             }
         }
         // Get assignment settings, use default settings on assignment creation.
         $plagiarismvalues = $this->get_settings($cmid);
         /* If Turnitin is disabled and we don't have settings (we're editing an existing assignment that was created without Turnitin enabled)
          * Then we pass NULL for the $cmid to ensure we have the default settings should they enable Turnitin.
          */
         if (empty($plagiarismvalues["use_turnitin"]) && count($plagiarismvalues) <= 2) {
             $savedvalues = $plagiarismvalues;
             $plagiarismvalues = $this->get_settings(NULL);
             // Ensure we reuse the saved setting for use Turnitin.
             if (isset($savedvalues["use_turnitin"])) {
                 $plagiarismvalues["use_turnitin"] = $savedvalues["use_turnitin"];
             }
         }
         $plagiarismelements = $this->get_settings_fields();
         $turnitinpluginview = new turnitinplugin_view();
         $plagiarismvalues["plagiarism_rubric"] = !empty($plagiarismvalues["plagiarism_rubric"]) ? $plagiarismvalues["plagiarism_rubric"] : 0;
         // Create/Edit course in Turnitin and join user to class.
         $course = $this->get_course_data($cmid, $COURSE->id);
         $turnitinpluginview->add_elements_to_settings_form($mform, $course, "activity", $cmid, $plagiarismvalues["plagiarism_rubric"]);
         // Disable all plagiarism elements if turnitin is not enabled.
         foreach ($plagiarismelements as $element) {
             if ($element != 'use_turnitin') {
                 // Ignore this var.
                 $mform->disabledIf($element, 'use_turnitin', 'eq', 0);
             }
         }
         // Check if files have already been submitted and disable exclude biblio and quoted if turnitin is enabled.
         if ($cmid != 0) {
             if ($DB->record_exists('plagiarism_turnitin_files', array('cm' => $cmid))) {
                 $mform->disabledIf('plagiarism_exclude_biblio', 'use_turnitin');
                 $mform->disabledIf('plagiarism_exclude_quoted', 'use_turnitin');
             }
         }
         // Set the default value for each option as the value we have stored.
         foreach ($plagiarismelements as $element) {
             if (isset($plagiarismvalues[$element])) {
                 $mform->setDefault($element, $plagiarismvalues[$element]);
             }
         }
     }
 }
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
require_once __DIR__ . '/../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/plagiarismlib.php';
require_once $CFG->dirroot . '/mod/turnitintooltwo/lib.php';
require_once __DIR__ . '/lib.php';
require_once __DIR__ . "/turnitinplugin_view.class.php";
$turnitinpluginview = new turnitinplugin_view();
require_login();
admin_externalpage_setup('plagiarismturnitin');
$context = context_system::instance();
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
$do = optional_param('do', "config", PARAM_ALPHA);
$action = optional_param('action', "", PARAM_ALPHA);
if (isset($_SESSION["notice"])) {
    $notice = $_SESSION["notice"];
    $notice["type"] = empty($_SESSION["notice"]["type"]) ? "general" : $_SESSION["notice"]["type"];
    unset($_SESSION["notice"]);
} else {
    $notice = null;
}
$plagiarismpluginturnitin = new plagiarism_plugin_turnitin();
$supported_mods = array('assign', 'forum', 'workshop');
 /**
  * Add the Turnitin settings form to an add/edit activity page
  *
  * @param object $mform
  * @param object $context
  * @return type
  */
 public function get_form_elements_module($mform, $context, $modulename = "")
 {
     global $DB, $COURSE;
     if (has_capability('plagiarism/turnitin:enable', $context)) {
         // Get Course module id and values.
         $cmid = optional_param('update', 0, PARAM_INT);
         // Only 2.4+ passes in the modulename so in 2.3 when adding a module
         // we can not differentiate whether plugin is enabled by module.
         if (!empty($modulename)) {
             $moduletiienabled = $this->get_config_settings($modulename);
             if (empty($moduletiienabled)) {
                 return;
             }
         }
         $plagiarismvalues = $this->get_settings($cmid);
         $plagiarismelements = $this->get_settings_fields();
         $turnitinpluginview = new turnitinplugin_view();
         $plagiarismvalues["plagiarism_rubric"] = !empty($plagiarismvalues["plagiarism_rubric"]) ? $plagiarismvalues["plagiarism_rubric"] : 0;
         // Create/Edit course in Turnitin and join user to class.
         $course = $this->get_course_data($cmid, $COURSE->id);
         $turnitinpluginview->add_elements_to_settings_form($mform, $course, "activity", $cmid, $plagiarismvalues["plagiarism_rubric"]);
         // Disable all plagiarism elements if turnitin is not enabled.
         foreach ($plagiarismelements as $element) {
             if ($element != 'use_turnitin') {
                 // Ignore this var.
                 $mform->disabledIf($element, 'use_turnitin', 'eq', 0);
             }
         }
         // Check if files have already been submitted and disable exclude biblio and quoted if turnitin is enabled.
         if ($cmid != 0) {
             if ($DB->record_exists('plagiarism_turnitin_files', array('cm' => $cmid))) {
                 $mform->disabledIf('plagiarism_exclude_biblio', 'use_turnitin');
                 $mform->disabledIf('plagiarism_exclude_quoted', 'use_turnitin');
             }
         }
         // Set the default value for each option as the value we have stored.
         foreach ($plagiarismelements as $element) {
             if (isset($plagiarismvalues[$element])) {
                 $mform->setDefault($element, $plagiarismvalues[$element]);
             }
         }
     }
 }
 public function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     require_once $CFG->dirroot . '/plagiarism/turnitin/turnitinplugin_view.class.php';
     $turnitinpluginview = new turnitinplugin_view();
     $turnitinpluginview->add_elements_to_settings_form($mform, array(), "defaults");
     $this->add_action_buttons(true);
 }