Example #1
0
/**
 * Abstracted version of print_error() to work with Moodle 1.8 through 2.0
 *
 * @param string $input The error string if module=NULL otherwise the language string called by get_string()
 * @param string $module The module string
 * @param string $param The parameter to send to use as the $a optional object in get_string()
 * @param string $file The file where the error occured
 * @param string $line The line number where the error occured
 */
function turnitintool_print_error($input, $module = NULL, $link = NULL, $param = NULL, $file = __FILE__, $line = __LINE__)
{
    global $CFG;
    turnitintool_activitylog($input, "PRINT_ERROR");
    if (is_null($module)) {
        $message = $input;
    } else {
        $message = get_string($input, $module, $param);
    }
    if (!empty($param_ajax) && $param_ajax) {
        header('HTTP/1.0 400 Bad Request');
        echo $message;
        $param_ajax = 0;
        exit;
    }
    $linkid = optional_param('id', null, PARAM_CLEAN);
    if (is_null($link) and substr_count($_SERVER["PHP_SELF"], "turnitintool/view.php") > 0) {
        $link = !is_null($linkid) ? $CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $linkid : $CFG->wwwroot;
    }
    if (isset($CFG->turnitin_enablediagnostic) and $CFG->turnitin_enablediagnostic == "1") {
        $message .= ' (' . basename($file) . ' | ' . $line . ')';
    }
    if (!headers_sent()) {
        // If there nothing in the output buffer then the loaderbar wasn't used print the error
        print_error('string', 'turnitintool', $link, '<span style="color: #888888;">' . $message . '</span>');
        exit;
    } else {
        // If there is something in the output buffer then the loaderbar was used and we need to redirect out and show an error afterwards
        // Reason for this is we have printed the HTML and BODY tags to the screen print_error will do the same and disrupt the loader bar javascript
        $errorarray['input'] = $input;
        $errorarray['module'] = $module;
        $errorarray['link'] = $link;
        $errorarray['param'] = $param;
        $errorarray['file'] = $file;
        $errorarray['line'] = $line;
        $_SESSION['turnitintool_errorarray'] = $errorarray;
        turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php');
        exit;
    }
}
Example #2
0
    $tutors = turnitintool_get_tiitutors($cm, $turnitintool);
    if (!is_null($tutors->error)) {
        $notice = $tutors->error;
    } else {
        $notice = null;
    }
}
if (!is_null($param_do) and $param_do == "changeowner") {
    turnitintool_ownerprocess($cm, $turnitintool, $param_owner);
    turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=tutors');
    exit;
}
if (!is_null($param_do) and $turnitintool->autoupdates == 1 and $param_do == "allsubmissions" and !is_null($param_anonid)) {
    $loaderbar = new turnitintool_loaderbarclass(3);
    turnitintool_revealuser($cm, $turnitintool, $post, $loaderbar);
    turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions&update=1');
    exit;
}
if (!is_null($param_updategrade) or isset($post['updategrade']) or isset($post["updategrade_x"])) {
    turnitintool_update_form_grades($cm, $turnitintool, $post);
}
if (!is_null($param_up)) {
    // Manual Submission to Turnitin
    if (!($submission = turnitintool_get_record('turnitintool_submissions', 'id', $param_up))) {
        print_error('submissiongeterror', 'turnitintool');
        exit;
    }
    turnitintool_upload_submission($cm, $turnitintool, $submission);
    exit;
}
if (!is_null($param_submissiontype) and $param_do == 'submissions') {
                        array_pop($split);
                        $muser->email = join('.', $split);
                    }
                    $tii = new turnitintool_commclass(null, $muser->firstname, $muser->lastname, $muser->email, $tuser->turnitin_utp, $loaderbar);
                    $tii->createUser($post, get_string('userprocess', 'turnitintool'));
                    $user = new stdClass();
                    $user->id = $userlink;
                    $user->turnitin_uid = $tii->getRerror() ? 0 : $tii->getUserID();
                    turnitintool_update_record('turnitintool_users', $user);
                    unset($tii);
                } else {
                    turnitintool_delete_records('turnitintool_users', 'id', $userlink);
                }
            }
            unset($loader);
            turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/extras.php?do=unlinkusers');
        }
        turnitintool_header(NULL, NULL, $_SERVER["REQUEST_URI"], get_string("modulenameplural", "turnitintool"), $SITE->fullname);
        echo '<div id="turnitintool_style">';
        turnitintool_box_start('generalbox boxwidthwide boxaligncenter', 'general');
        echo '<b>' . get_string('unlinkrelinkusers', 'turnitintool') . '</b><br /><br />';
        echo '<form method="POST" id="turnitin_unlink" action="' . $CFG->wwwroot . '/mod/turnitintool/extras.php?do=unlinkusers"><div style="height: 400px;overflow: auto;">
';
        if ($userrows = turnitintool_get_records('turnitintool_users')) {
            foreach ($userrows as $userdata) {
                if (!($user = turnitintool_get_record('user', 'id', $userdata->userid))) {
                    $user->id = $user->userid;
                    $user->lastname = get_string('nonmoodleuser', 'turnitintool');
                    $user->firstname = '';
                    $user->email = get_string('notavailableyet', 'turnitintool');
                }
    $notice = turnitintool_delete_part($cm, $turnitintool, $param_delpart);
}
if (!is_null($param_submitted) and $param_do == 'notes') {
    $notice = turnitintool_process_notes($cm, $turnitintool, $param_s, $post);
}
if (!is_null($param_submitted) and $param_do == 'options') {
    $notice = turnitintool_process_options($cm, $turnitintool, $post);
}
if (!is_null($param_do) and $turnitintool->autoupdates == 1 and ($param_do == 'allsubmissions' or $param_do == 'submissions')) {
    if ($param_do == 'submissions') {
        $getuser = $USER->id;
    } else {
        $getuser = NULL;
    }
    if (turnitintool_update_all_report_scores($cm, $turnitintool, 0)) {
        turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=' . $param_do);
    }
}
add_to_log($course->id, "turnitintool", "view", "view.php?id={$cm->id}", "{$turnitintool->id}");
/// Print the page header
$strturnitintools = get_string("modulenameplural", "turnitintool");
$strturnitintool = get_string("modulename", "turnitintool");
if (!is_callable('build_navigation')) {
    $navigation = array(array('title' => $course->shortname, 'url' => $CFG->wwwroot . "/course/view.php?id={$course->id}", 'type' => 'course'), array('title' => $strturnitintools, 'url' => $CFG->wwwroot . "/mod/turnitintool/index.php?id={$course->id}", 'type' => 'activity'), array('title' => format_string($turnitintool->name), 'url' => '', 'type' => 'activityinstance'));
} else {
    $navigation = build_navigation('', $cm);
}
turnitintool_header($cm, $course, $_SERVER["REQUEST_URI"], $turnitintool->name, $SITE->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $strturnitintool), navmenu($course));
/// Check to see if groups are being used and abstract for 1.8 if neccessary
if (!is_callable('groups_get_activity_group')) {
    $changegroup = optional_param('group', -1, PARAM_INT);
 if (!is_callable("get_file_storage")) {
     turnitintool_print_error("moodle2only", "turnitintool");
     exit;
 }
 if (!is_null($param_fileid)) {
     if ($filedata = $DB->get_record("files", array("id" => $param_fileid, "component" => "mod_turnitintool", "pathnamehash" => $param_filehash))) {
         $submission = $DB->get_record("turnitintool_submissions", array("id" => $filedata->itemid));
     } else {
         turnitintool_print_error("submissiongeterror", "turnitintool");
         exit;
     }
     if (!is_null($param_filerem)) {
         $fs = get_file_storage();
         $file = $fs->get_file($filedata->contextid, 'mod_turnitintool', 'submission', $filedata->itemid, '/', $filedata->filename);
         $file->delete();
         turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/extras.php?do=files');
         exit;
     } else {
         $fs = get_file_storage();
         $file = $fs->get_file($filedata->contextid, 'mod_turnitintool', 'submission', $filedata->itemid, '/', $filedata->filename);
         $filename = isset($submission->submission_filename) ? $submission->submission_filename : $filedata->filename;
         try {
             send_stored_file($file, 0, 0, true, $filename);
         } catch (Exception $e) {
             send_stored_file($file, 0, 0, true, array("filename" => $filename));
         }
     }
 } else {
     turnitintool_header(NULL, NULL, $_SERVER["REQUEST_URI"], get_string("modulenameplural", "turnitintool"), $SITE->fullname);
     $modules = $DB->get_record('modules', array('name' => 'turnitintool'));
     echo '