Example #1
0
 public static function gradeTable($GRADE_DETAIL_CLASS)
 {
     global $CFG, $OUTPUT, $USER, $LINK;
     // Require CONTEXT, USER, and LINK
     $LAUNCH = LTIX::requireData();
     if (!$USER->instructor) {
         die("Requires instructor role");
     }
     $p = $CFG->dbprefix;
     // Get basic grade data
     $query_parms = array(":LID" => $LINK->id);
     $orderfields = array("R.updated_at", "displayname", "email", "grade");
     $searchfields = $orderfields;
     $sql = "SELECT R.user_id AS user_id, displayname, email,\n                grade, note, R.updated_at AS updated_at\n            FROM {$p}lti_result AS R\n            JOIN {$p}lti_user AS U ON R.user_id = U.user_id\n            WHERE R.link_id = :LID";
     // View
     $OUTPUT->header();
     $OUTPUT->bodyStart();
     $OUTPUT->flashMessages();
     $OUTPUT->welcomeUserCourse();
     if (isset($GRADE_DETAIL_CLASS) && is_object($GRADE_DETAIL_CLASS)) {
         $detail = $GRADE_DETAIL_CLASS;
     } else {
         $detail = false;
     }
     Table::pagedAuto($sql, $query_parms, $searchfields, $orderfields, "grade-detail.php");
     // Since this is in a popup, put out a done button
     $OUTPUT->closeButton();
     $OUTPUT->footer();
 }
Example #2
0
function gradeUpdateJson($newdata = false)
{
    global $CFG, $PDOX, $LINK;
    if ($newdata == false) {
        return;
    }
    if (is_string($newdata)) {
        $newdata = json_decode($newdata, true);
    }
    $LTI = LTIX::requireData(array(LTIX::LINK));
    $row = gradeLoad();
    $data = array();
    if ($row !== false && isset($row['json'])) {
        $data = json_decode($row['json'], true);
    }
    $changed = false;
    foreach ($newdata as $k => $v) {
        if (!isset($data[$k]) || $data[$k] != $v) {
            $data[$k] = $v;
            $changed = true;
        }
    }
    if ($changed === false) {
        return;
    }
    $jstr = json_encode($data);
    $stmt = $PDOX->queryDie("UPDATE {$CFG->dbprefix}lti_result SET json = :json, updated_at = NOW()\n            WHERE result_id = :RID", array(':json' => $jstr, ':RID' => $LINK->result_id));
}
Example #3
0
 public static function serveContent()
 {
     global $CFG, $CONTEXT, $PDOX;
     // Sanity checks
     $LAUNCH = LTIX::requireData(LTIX::CONTEXT);
     $id = $_REQUEST['id'];
     if (strlen($id) < 1) {
         die("File not found");
     }
     $p = $CFG->dbprefix;
     $stmt = $PDOX->prepare("SELECT contenttype, content, file_name FROM {$p}blob_file\n                    WHERE file_id = :ID AND context_id = :CID");
     $stmt->execute(array(":ID" => $id, ":CID" => $CONTEXT->id));
     $row = $stmt->fetch(\PDO::FETCH_ASSOC);
     if ($row === false) {
         error_log('File not loaded: ' . $id);
         die("File not loaded");
     }
     if (!BlobUtil::safeFileSuffix($row['file_name'])) {
         error_log('Unsafe file suffix: ' . $row['file_name']);
         die('Unsafe file suffix');
     }
     $mimetype = $row['contenttype'];
     // die($mimetype);
     if (strlen($mimetype) > 0) {
         header('Content-Type: ' . $mimetype);
     }
     // header('Content-Disposition: attachment; filename="'.$fn.'"');
     // header('Content-Type: text/data');
     echo $row['content'];
 }
Example #4
0
 /**
  * Retrieve an array of all of the link level settings
  *
  * If there are no settings, return an empty array.  
  *
  * This routine also looks for legacy custom fields and treats
  * them as defaults for settings if the corresponding key is not
  * already present in settings.  This will slowly convert LTI 
  * 1.x custom parameters under the control of the LMS to LTI 2.x 
  * style settings under control of our local tools.
  */
 public static function linkGetAll()
 {
     global $CFG, $PDOX, $LINK;
     if (!isset($_SESSION['lti'])) {
         return array();
     }
     if (isset($_SESSION['lti']['link_settings_merge'])) {
         return $_SESSION['lti']['link_settings_merge'];
     }
     $legacy_fields = array('dologin', 'close', 'due', 'timezone', 'penalty_time', 'penalty_cost');
     $defaults = array();
     foreach ($legacy_fields as $k) {
         $value = LTIX::customGet($k);
         $defaults[$k] = $value;
     }
     if (isset($_SESSION['lti']['link_settings'])) {
         $json = $_SESSION['lti']['link_settings'];
         if (strlen($json) < 0) {
             return $defaults;
         }
         $retval = json_decode($json, true);
         // No objects
         $retval = array_merge($defaults, $retval);
         $_SESSION['lti']['link_settings_array'] = $retval;
         return $retval;
     }
     // Not in session - retrieve from the database
     // We cannot assume the $LINK is fully set up yet...
     if (!isset($_SESSION['lti']['link_id'])) {
         return $defaults;
     }
     $row = $PDOX->rowDie("SELECT settings FROM {$CFG->dbprefix}lti_link WHERE link_id = :LID", array(":LID" => $_SESSION['lti']['link_id']));
     if ($row === false) {
         return $defaults;
     }
     $json = $row['settings'];
     if ($json === null) {
         return $defaults;
     }
     $retval = json_decode($json, true);
     // No objects
     $retval = array_merge($defaults, $retval);
     // Store in session for later
     $_SESSION['lti']['link_settings'] = $json;
     $_SESSION['lti']['link_settings_array'] = $retval;
     return $retval;
 }
Example #5
0
function webauto_test_passed($grade, $url)
{
    global $USER, $OUTPUT;
    success_out("Test passed - congratulations");
    if ($USER->displayname === false || !isset($_SESSION['lti'])) {
        line_out('Not setup to return a grade..');
        return false;
    }
    $LTI = $_SESSION['lti'];
    $old_grade = isset($LTI['grade']) ? $LTI['grade'] : 0.0;
    if ($grade < $old_grade) {
        line_out('New grade is not higher than your previous grade=' . $old_grade);
        line_out('Sending your previous high score');
        $grade = $old_grade;
    }
    gradeUpdateJson(json_encode(array("url" => $url)));
    $debug_log = array();
    $retval = LTIX::gradeSend($grade, false, $debug_log);
    $OUTPUT->dumpDebugArray($debug_log);
    if ($retval == true) {
        $success = "Grade sent to server (" . $grade . ")";
    } else {
        if (is_string($retval)) {
            $failure = "Grade not sent: " . $retval;
        } else {
            echo "<pre>\n";
            var_dump($retval);
            echo "</pre>\n";
            $failure = "Internal error";
        }
    }
    if (strlen($success) > 0) {
        success_out($success);
        error_log($success);
    } else {
        if (strlen($failure) > 0) {
            error_out($failure);
            error_log($failure);
        } else {
            error_log("No status");
        }
    }
    return true;
}
Example #6
0
count = 0
for line in fh:
    print line.strip()
    count = count + 1

print count,"Lines"';
$CHECKS = false;
$EX = false;

// Check which exercise we are supposed to do - settings, then custom, then 
// GET
if ( isset($oldsettings['exercise']) && $oldsettings['exercise'] != '0' ) {
    $ex = $oldsettings['exercise'];
} else {
    $ex = LTIX::customGet('exercise');
}
if ( $ex === false && isset($_REQUEST["exercise"]) ) {
    $ex = $_REQUEST["exercise"];
}
if ( $ex !== false && $ex != "code" ) {
    if ( isset($EXERCISES[$ex]) ) $EX = $EXERCISES[$ex];
    if ( $EX !== false ) {
        $CODE = '';
        $QTEXT = $EX["qtext"];
        $DESIRED = $EX["desired"];
        $DESIRED2 = isset($EX["desired2"]) ? $EX["desired2"] : '';
        $DESIRED = rtrim($DESIRED);
        $DESIRED2 = rtrim($DESIRED2);
        if ( isset($EX["code"]) ) $CODE = $EX["code"];
        if ( isset($EX["checks"]) ) $CHECKS = json_encode($EX["checks"]);
Example #7
0
require_once "names.php";
require_once "locations.php";
use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
use Tsugi\Util\Net;
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
if (!$USER->instructor) {
    die('Must be instructor');
}
$sanity = array('urllib' => 'You should use urllib to retrieve the data from the API', 'urlencode' => 'You should use urlencode add parameters to the API url', 'json' => 'You should use the json library to parse the API data');
echo "<pre>\n";
echo "Running test...\n";
// Run though all the locations
// var_dump($LOCATIONS);
$url = LTIX::curPageUrlScript();
$i = 500;
foreach ($LOCATIONS as $key => $location) {
    // echo(htmlentities($location)."\n");
    $api_url = str_replace('geo_test.php', 'data/geojson', $url);
    $sample_url = $api_url . '?sensor=false&address=' . urlencode($location);
    $sample_data = Net::doGet($sample_url);
    $sample_count = strlen($sample_data);
    $response = Net::getLastHttpResponse();
    $sample_json = json_decode($sample_data);
    if ($response != 200 || $sample_json == null || !isset($sample_json->results[0])) {
        echo "*** Bad response={$response} url={$sample_url} json_error=" . json_last_error_msg() . "\n";
        echo jsonIndent($sample_data);
        continue;
    }
    // echo("<pre>\n");echo(jsonIndent(json_encode($sample_json)));echo("</pre>\n");
Example #8
0
    }
    unset($_SESSION['peer_submit_id']);
    $submit_id = $_POST['submit_id'] + 0;
    $stmt = $PDOX->queryReturnError("INSERT INTO {$p}peer_grade\n            (submit_id, user_id, points, note, created_at, updated_at)\n            VALUES ( :SID, :UID, :POINTS, :NOTE, NOW(), NOW())\n            ON DUPLICATE KEY UPDATE points = :POINTS, note = :NOTE, updated_at = NOW()", array(':SID' => $submit_id, ':UID' => $USER->id, ':POINTS' => $points, ':NOTE' => $_POST['note']));
    Cache::clear('peer_grade');
    if (!$stmt->success) {
        $_SESSION['error'] = $stmt->errorImplode;
        header('Location: ' . addSession($url_goback));
        return;
    }
    // Attempt to update the user's grade, may take a second..
    $grade = computeGrade($assn_id, $assn_json, $user_id);
    $_SESSION['success'] = 'Grade submitted';
    if ($grade > 0) {
        $result = lookupResult($LTI, $user_id);
        $status = LTIX::gradeSend($grade, $result);
        // This is the slow bit
        if ($status === true) {
            $_SESSION['success'] = 'Grade submitted to server';
        } else {
            error_log("Problem sending grade " . $status);
        }
    }
    header('Location: ' . addSession($url_goback));
    return;
}
unset($_SESSION['peer_submit_id']);
$submit_id = false;
$submit_json = null;
if ($user_id === false) {
    // Load the the 10 oldest ungraded submissions
Example #9
0
 if ($status === true) {
     echo 'Grade submitted to server' . "<br/>\n";
     $success++;
 } else {
     echo '<pre class="alert alert-danger">' . "\n";
     $msg = "result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " server_grade=" . $row['server_grade'] . "\n" . "error=" . $status;
     echo_log("Problem Sending Grade: " . session_id() . "\n" . $msg . "\n" . "result_url=" . $row['reult_url'] . " service_key=" . $row['service_key'] . " sourcedid=" . $row['sourcedid']);
     echo "</pre>\n";
     $OUTPUT->togglePre("Error retrieving new grade at " . $count, $LastPOXGradeResponse);
     flush();
     echo "Problem sending grade " . $status . "<br/>\n";
     $fail++;
     continue;
 }
 // Check to see if the grade we sent is really there - Also updates our local table
 $server_grade = LTIX::gradeGet($row);
 if (is_string($server_grade)) {
     echo '<pre class="alert alert-danger">' . "\n";
     $msg = "result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " updated=" . $row['updated_at'] . "\n" . "server_grade=" . $row['server_grade'] . " retrieved=" . $row['retrieved_at'] . "\n" . "error=" . $server_grade;
     echo_log("Problem Updating Grade: " . session_id() . "\n" . $msg . "\n" . "result_url=" . $row['reult_url'] . " service_key=" . $row['service_key'] . " sourcedid=" . $row['sourcedid']);
     echo "</pre>\n";
     error_log("Error re-retrieving grade: " . session_id() . ' result_id=' . $row['result_id'] . "result_url=" . $row['reult_url'] . ' sourcedid=' + $row['sourcedid'] + ' service_key=' + $row['service_key']);
     $OUTPUT->togglePre("Error retrieving new grade at " . $count, $LastPOXGradeResponse);
     flush();
     $fail++;
     continue;
 } else {
     if ($server_grade != $row['grade']) {
     } else {
     }
 }
Example #10
0
headerJson();
// Nothing for us to do
if (!isset($_GET[session_name()])) {
    echo json_encode(array("error" => "No session"));
    return;
}
if (isset($_COOKIE[session_name()])) {
    echo json_encode(array("status" => 'done'));
    return;
}
if (!isset($_GET['top'])) {
    echo json_encode(array("error" => "Need top= parameter"));
    return;
}
// Grab the session
$LTI = LTIX::requireData(LTIX::USER);
// This has already been set by someone so nothing to do
if (isset($_COOKIE['TSUGI_TOP_SESSION'])) {
    unset($_SESSION['TOP_CHECK']);
    // No point in further checks
    echo json_encode(array("top_session" => $_COOKIE['TSUGI_TOP_SESSION']));
    return;
}
// We are not the top frame
if ($_GET['top'] != 'true') {
    unset($_SESSION['TOP_CHECK']);
}
// No more checks are needed
if (!isset($_SESSION['TOP_CHECK']) || $_SESSION['TOP_CHECK'] < 1) {
    echo json_encode(array("status" => 'done'));
    return;
// Sanity checks
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
$OUTPUT->header();
$OUTPUT->bodyStart();
$OUTPUT->flashMessages();
$OUTPUT->welcomeUserCourse();
if (!$USER->instructor) {
    echo "<p>This tool must be launched by the instructor</p>";
    $OUTPUT->footer();
    exit;
}
// See https://canvas.instructure.com/doc/api/file.link_selection_tools.html
// Needed return values
$content_return_types = LTIX::postGet("ext_content_return_types", false);
$content_return_url = LTIX::postGet("ext_content_return_url", false);
if (strlen($content_return_url) < 1) {
    lmsDie("Missing ext_content_return_url");
}
if (strpos($content_return_types, "lti_launch_url") === false) {
    lmsDie("This tool requires ext_content_return_types=lti_launch_url");
}
// Scan the tools folders for registration settings
$tools = findFiles("register.php", "../");
if (count($tools) < 1) {
    lmsDie("No register.php files found...<br/>\n");
}
echo "<ul>\n";
$toolcount = 0;
foreach ($tools as $tool) {
    $path = str_replace("../", "", $tool);
Example #12
0
    $assn_json = json_decode($row['json']);
    $assn_id = $row['assn_id'];
}
if ($assn_id == false) {
    jsonError('This assignment is not yet set up');
    return;
}
// Compute the user's grade
$grade = computeGrade($assn_id, $assn_json, $user_id);
if ($grade <= 0) {
    jsonError('Nothing to grade for this user', $row);
    return;
}
// Lookup the result row if we are grading the non-current user
$result = false;
if ($user_id != $USER->id) {
    $result = lookupResult($LTI, $user_id);
}
// Send the grade
$debug_log = array();
$status = LTIX::gradeSend($grade, $result, $debug_log);
// This is the slow bit
if ($status === true) {
    if ($user_id != $USER->id) {
        jsonOutput(array("status" => $status, "debug" => $debug_log));
    } else {
        jsonOutput(array("status" => $status, "grade" => $grade, "debug" => $debug_log));
    }
} else {
    jsonError($status, $debug_log);
}
Example #13
0
     echo "<h1>" . htmlent_utf8($title) . "</h1>\n";
     echo "<p>" . htmlent_utf8($text) . "</p>\n";
     $script = isset($REGISTER_LTI2['script']) ? $REGISTER_LTI2['script'] : "index.php";
     $path = $CFG->wwwroot . '/' . str_replace("register.php", $script, $path);
     // Title is for the href and text is for display
     $json = LTI::getLtiLinkJSON($path, $title, $title, false, $fa_icon);
     $retval = json_encode($json);
     $parms = array();
     $parms["lti_message_type"] = "ContentItemSelection";
     $parms["lti_version"] = "LTI-1p0";
     $parms["content_items"] = $retval;
     $data = LTIX::postGet('data');
     if ($data) {
         $parms['data'] = $data;
     }
     $parms = LTIX::signParameters($parms, $result_url, "POST", "Install Tool");
     $endform = '<a href="index.php" class="btn btn-warning">Back to Store</a>';
     $content = LTI::postLaunchHTML($parms, $result_url, true, false, $endform);
     echo $content;
 } else {
     echo '<div style="border: 2px, solid, red;" class="card">';
     if ($fa_icon) {
         echo '<a href="index.php?install=' . urlencode($tool) . '">';
         echo '<i class="fa ' . $fa_icon . ' fa-2x" style="color: #1894C7; float:right; margin: 2px"></i>';
         echo '</a>';
     }
     echo '<p><strong>' . htmlent_utf8($title) . "</strong></p>";
     echo '<p>' . htmlent_utf8($text) . "</p>\n";
     echo '<center><a href="index.php?install=' . urlencode($tool) . '" class="btn btn-default" role="button">Details</a></center>';
     echo "</div>\n";
 }
Example #14
0
function dataUrl($file)
{
    global $GLOBAL_PYTHON_DATA_URL;
    if (is_string($GLOBAL_PYTHON_DATA_URL)) {
        return $GLOBAL_PYTHON_DATA_URL . $file;
    }
    $url = LTIX::curPageUrlScript();
    $retval = str_replace('index.php', 'data/' . $file, $url);
    return $retval;
}
Example #15
0
        header('Location: ' . addSession('student.php?user_id=' . $user_id));
    }
    return;
}
// Compute grade
$computed_grade = computeGrade($assn_id, $assn_json, $user_id);
// Does not cache
if (isset($_POST['resendSubmit'])) {
    $result = lookupResult($LTI, $user_id);
    // Does not cache
    // Force a resend
    $_SESSION['lti']['grade'] = -1;
    // Force a resend
    $result['grade'] = -1;
    $debug_log = array();
    $status = LTIX::gradeSend($computed_grade, $result, $debug_log);
    // This is the slow bit
    if ($status === true) {
        $_SESSION['success'] = 'Grade submitted to server';
    } else {
        error_log("Problem sending grade " . $status);
        $_SESSION['error'] = 'Error: ' . $status;
    }
    $_SESSION['debug_log'] = $debug_log;
    header('Location: ' . addSession('student.php?user_id=' . $user_id));
    return;
}
// Retrieve our grades...
$grades_received = retrieveSubmissionGrades($submit_id);
// Handle incoming post to delete a grade entry
if (isset($_POST['grade_id']) && isset($_POST['deleteGrade'])) {
Example #16
0
    function doAnalytics()
    {
        global $CFG;
        if ($CFG->analytics_key) {
            ?>
    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '<?php 
            echo $CFG->analytics_key;
            ?>
']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        // ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';

        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    <?php 
            if (LTIX::sessionGet('key_key')) {
                echo "_gaq.push(['_setCustomVar', 1, 'consumer_key', '" . $_SESSION['lti']['key_key'] . "', 2]);\n";
            }
            if (LTIX::sessionGet('context_id')) {
                echo "_gaq.push(['_setCustomVar', 2, 'context_id', '" . $_SESSION['lti']['context_id'] . "', 2]);\n";
            }
            if (LTIX::sessionGet('context_title')) {
                echo "_gaq.push(['_setCustomVar', 3, 'context_title', '" . $_SESSION['lti']['context_title'] . "', 2]);\n";
            }
            echo "</script>\n";
        }
        // if analytics is on...
    }
Example #17
0
 /**
  * Send a grade and update our local copy
  *
  * Call the right LTI service to send a new grade up to the server.
  * update our local cached copy of the server_grade and the date
  * retrieved. This routine pulls the key and secret from the LTIX
  * session to avoid crossing cross tennant boundaries.
  *
  * @param $grade A new grade - floating point number between 0.0 and 1.0
  * @param $row An optional array with the data that has the result_id, sourcedid,
  * and service (url) if this is not present, the data is pulled from the LTI
  * session for the current user/link combination.
  * @param $debug_log An (optional) array (by reference) that returns the
  * steps that were taken.
  * Each entry is an array with the [0] element a message and an optional [1]
  * element as some detail (i.e. like a POST body)
  *
  * @return mixed If this works it returns true.  If not, you get
  * a string with an error.
  *
  */
 public function gradeSend($grade, $row = false, &$debug_log = false)
 {
     global $CFG, $USER;
     global $LastPOXGradeResponse;
     $LastPOXGradeResponse = false;
     $PDOX = LTIX::getConnection();
     // Secret and key from session to avoid crossing tenant boundaries
     $key_key = LTIX::sessionGet('key_key');
     $secret = LTIX::sessionGet('secret');
     if ($row !== false) {
         $result_url = isset($row['result_url']) ? $row['result_url'] : false;
         $sourcedid = isset($row['sourcedid']) ? $row['sourcedid'] : false;
         $service = isset($row['service']) ? $row['service'] : false;
         // Fall back to session if it is missing
         if ($service === false) {
             $service = LTIX::sessionGet('service');
         }
         $result_id = isset($row['result_id']) ? $row['result_id'] : false;
     } else {
         $result_url = LTIX::sessionGet('result_url');
         $sourcedid = LTIX::sessionGet('sourcedid');
         $service = LTIX::sessionGet('service');
         $result_id = LTIX::sessionGet('result_id');
     }
     // Update result in the database and in the LTI session area and
     // our local copy
     $_SESSION['lti']['grade'] = $grade;
     $this->grade = $grade;
     // Update the local copy of the grade in the lti_result table
     if ($PDOX !== false && $result_id !== false) {
         $stmt = $PDOX->queryReturnError("UPDATE {$CFG->dbprefix}lti_result SET grade = :grade,\n                    updated_at = NOW() WHERE result_id = :RID", array(':grade' => $grade, ':RID' => $result_id));
         if ($stmt->success) {
             $msg = "Grade updated result_id=" . $result_id . " grade={$grade}";
         } else {
             $msg = "Grade NOT updated result_id=" . $result_id . " grade={$grade}";
         }
         error_log($msg);
         if (is_array($debug_log)) {
             $debug_log[] = array($msg);
         }
     }
     if ($key_key == false || $secret === false || $sourcedid === false || $service === false || !isset($USER)) {
         error_log("Result::gradeSend stored data locally");
         return false;
     }
     // TODO: Fix this
     $comment = "";
     if (strlen($result_url) > 0) {
         $status = LTI::sendJSONGrade($grade, $comment, $result_url, $key_key, $secret, $debug_log);
     } else {
         $status = LTI::sendPOXGrade($grade, $sourcedid, $service, $key_key, $secret, $debug_log);
     }
     if ($status === true) {
         $msg = 'Grade sent ' . $grade . ' to ' . $sourcedid . ' by ' . $USER->id;
         if (is_array($debug_log)) {
             $debug_log[] = array($msg);
         }
         error_log($msg);
     } else {
         $msg = 'Grade failure ' . $grade . ' to ' . $sourcedid . ' by ' . $USER->id;
         if (is_array($debug_log)) {
             $debug_log[] = array($msg);
         }
         error_log($msg);
         return $status;
     }
     return $status;
 }
Example #18
0
require_once "../../config.php";
require_once $CFG->dirroot . "/pdo.php";
require_once $CFG->dirroot . "/lib/lms_lib.php";
require_once $CFG->dirroot . "/core/gradebook/lib.php";
use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
use Tsugi\Util\Caliper;
// Retrieve the launch data if present
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
$displayname = $USER->displayname;
if (isset($_POST['caliper'])) {
    $caliper = Caliper::sensorCanvasPageView(LTIX::sessionGet('user_key'), $CFG->wwwroot, "samples/grade/index.php");
    $_SESSION['caliper'] = $caliper;
    $debug_log = array();
    $retval = LTIX::caliperSend($caliper, 'application/json', $debug_log);
    /*
    echo("<pre>\n");
    var_dump($caliper);
    echo("</pre>\n");
    die();
    */
    if ($retval) {
        $_SESSION['success'] = "Caliper sent.";
    } else {
        $_SESSION['error'] = "Caliper attempt failed.";
    }
    $_SESSION['debuglog'] = $debug_log;
    header('Location: ' . addSession('index.php'));
    return;
}
Example #19
0
File: LTIX.php Project: na1iu/tsugi
 /**
  * Send a Caliper Body to the correct URL using the key and secret
  *
  * This is not yet a standard or production - it uses the Canvas 
  * extension only.
  * 
  */
 public static function caliperSend($caliperBody, $content_type = 'application/json', &$debug_log = false)
 {
     $caliperURL = LTIX::postGet('custom_sub_canvas_caliper_url');
     if (strlen($caliperURL) == 0) {
         if (is_array($debug_log)) {
             $debug_log[] = array('custom_sub_canvas_caliper_url not found in launch data');
         }
         return false;
     }
     $key_key = self::sessionGet('key_key');
     $secret = self::sessionGet('secret');
     $retval = LTI::sendJSONBody("POST", $caliperBody, $content_type, $caliperURL, $key_key, $secret, $debug_log);
     return $retval;
 }
Example #20
0
<?php

require_once "../../config.php";
require_once $CFG->dirroot . "/pdo.php";
require_once $CFG->dirroot . "/lib/lms_lib.php";
require_once "blob_util.php";
use Tsugi\Core\LTIX;
// Sanity checks
$LTI = LTIX::requireData(array(LTIX::CONTEXT, LTIX::LINK));
// Model
$p = $CFG->dbprefix;
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == 1) {
    $_SESSION['error'] = 'Error: Maximum size of ' . maxUpload() . 'MB exceeded.';
    header('Location: ' . addSession('index.php'));
    return;
}
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == 0) {
    $filename = basename($_FILES['uploaded_file']['name']);
    if (strpos($filename, '.php') !== false) {
        $_SESSION['error'] = 'Error: Wrong file type.';
        header('Location: ' . addSession('index.php'));
        return;
    }
    $fp = fopen($_FILES['uploaded_file']['tmp_name'], "rb");
    $stmt = $PDOX->prepare("INSERT INTO {$p}sample_blob\n        (context_id, file_name, contenttype, content, created_at)\n        VALUES (?, ?, ?, ?, NOW())");
    $stmt->bindParam(1, $CONTEXT->id);
    $stmt->bindParam(2, $filename);
    $stmt->bindParam(3, $_FILES['uploaded_file']['type']);
    $stmt->bindParam(4, $fp, PDO::PARAM_LOB);
    $PDOX->beginTransaction();
    $stmt->execute();
Example #21
0
    function doAnalytics()
    {
        global $CFG;
        if ($CFG->universal_analytics) {
            ?>
            <script>
              (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
              (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
              m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
              })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
 
              ga('create', '<?php 
            echo $CFG->universal_analytics;
            ?>
', 'auto');
              ga('send', 'pageview');
 
            </script>
	<?php 
        }
        if ($CFG->analytics_key) {
            ?>
    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '<?php 
            echo $CFG->analytics_key;
            ?>
']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        // ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';

        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    <?php 
            if (LTIX::sessionGet('key_key')) {
                echo "_gaq.push(['_setCustomVar', 1, 'consumer_key', '" . $_SESSION['lti']['key_key'] . "', 2]);\n";
            }
            if (LTIX::sessionGet('context_id')) {
                echo "_gaq.push(['_setCustomVar', 2, 'context_id', '" . $_SESSION['lti']['context_id'] . "', 2]);\n";
            }
            if (LTIX::sessionGet('context_title')) {
                echo "_gaq.push(['_setCustomVar', 3, 'context_title', '" . $_SESSION['lti']['context_title'] . "', 2]);\n";
            }
            echo "</script>\n";
        }
        // if analytics is on...
    }
Example #22
0
function loadLinkInfo($link_id)
{
    global $CFG, $PDOX;
    $LTI = LTIX::requireData(LTIX::CONTEXT);
    $cacheloc = 'lti_link';
    $row = Cache::check($cacheloc, $link_id);
    if ($row != false) {
        return $row;
    }
    $stmt = $PDOX->queryDie("SELECT title FROM {$CFG->dbprefix}lti_link\n            WHERE link_id = :LID AND context_id = :CID", array(":LID" => $link_id, ":CID" => $LTI['context_id']));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    Cache::set($cacheloc, $link_id, $row);
    return $row;
}
Example #23
0
         } else {
             if ($server_grade > 0.0) {
                 $newrow['note'] .= ' Server grade retrieved.';
             } else {
                 $newrow['note'] .= ' Server grade checked.';
             }
         }
         $row['server_grade'] = $server_grade;
         $newrow['retrieved_at'] = $row['time_now'];
         $row['retrieved_at'] = $row['time_now'];
     }
     // Now check to see if we need to update the server_grade
     if ($row['server_grade'] < $row['grade']) {
         error_log("Patching server grade: " . session_id() . " result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " updated=" . $row['updated_at'] . "\n" . "server_grade=" . $row['server_grade'] . " retrieved=" . $row['retrieved_at']);
         $debug_log = array();
         $status = LTIX::gradeSend($row['grade'], $row, $debug_log);
         if ($status === true) {
             $newrow['note'] .= " Server grade updated.";
         } else {
             echo '<pre class="alert alert-danger">' . "\n";
             $msg = "result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " updated=" . $row['updated_at'] . "\n" . "server_grade=" . $row['server_grade'] . " retrieved=" . $row['retrieved_at'] . "\n" . "error=" . $server_grade;
             echo "Problem Updating Grade: " . session_safe_id() . " " . $msg;
             error_log("Problem Updating Grade: " . session_id() . "\n" . $msg . "\n" . "service=" . $row['service'] . " sourcedid=" . $row['sourcedid']);
             echo "\nProblem Retrieving Grade - Please take a screen shot of this page.\n";
             echo "</pre>\n";
             $newrow['note'] .= " Problem Updating Server Grade";
         }
     }
     $newrows[] = $newrow;
 }
 Table::pagedTable($newrows, $searchfields);
Example #24
0
use Tsugi\Util\LTI;
use Tsugi\Util\Caliper;
// Retrieve the launch data if present
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
$displayname = $USER->displayname;
if (isset($_POST['grade'])) {
    $gradetosend = $_POST['grade'] + 0.0;
    if ($gradetosend < 0.0 || $gradetosend > 1.0) {
        $_SESSION['error'] = "Grade out of range";
        header('Location: ' . addSession('index.php'));
        return;
    }
    // Use LTIX to send the grade back to the LMS.
    $debug_log = array();
    $retval = LTIX::gradeSend($gradetosend, false, $debug_log);
    $_SESSION['debug_log'] = $debug_log;
    if ($retval === true) {
        $_SESSION['success'] = "Grade {$gradetosend} sent to server.";
    } else {
        if (is_string($retval)) {
            $_SESSION['error'] = "Grade not sent: " . $retval;
        } else {
            echo "<pre>\n";
            var_dump($retval);
            echo "</pre>\n";
            die;
        }
    }
    // Redirect to ourself
    header('Location: ' . addSession('index.php'));
Example #25
0
<?php

require_once 'config.php';
require_once 'pdo.php';
require_once 'lib/lms_lib.php';
use Tsugi\Core\LTIX;
$session_id = LTIX::setupSession();
// See if we have a custom assignment setting.
if (!isset($_POST['custom_assn'])) {
    require "lti/noredir.php";
    return;
} else {
    $url = $_POST['custom_assn'];
    $_SESSION['assn'] = $_POST['custom_assn'];
}
// Send us to where we are going next...
$query = false;
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) {
    $query = true;
    $url .= '?' . $_SERVER['QUERY_STRING'];
}
$location = addSession($url);
session_write_close();
// To avoid any race conditions...
if (headers_sent()) {
    echo '<p><a href="' . $url . '">Click to continue</a></p>';
} else {
    header('Location: ' . $location);
}
Example #26
0
Output::headerJson();
// Nothing for us to do
if (!isset($_GET[session_name()])) {
    echo json_encode(array("error" => "No session"));
    return;
}
if (isset($_COOKIE[session_name()])) {
    echo json_encode(array("status" => 'done'));
    return;
}
if (!isset($_GET['top'])) {
    echo json_encode(array("error" => "Need top= parameter"));
    return;
}
// Grab the session
$LAUNCH = LTIX::requireData(LTIX::USER);
// This has already been set by someone so nothing to do
if (isset($_COOKIE['TSUGI_TOP_SESSION'])) {
    unset($_SESSION['TOP_CHECK']);
    // No point in further checks
    echo json_encode(array("top_session" => $_COOKIE['TSUGI_TOP_SESSION']));
    return;
}
// We are not the top frame
if ($_GET['top'] != 'true') {
    unset($_SESSION['TOP_CHECK']);
}
// No more checks are needed
if (!isset($_SESSION['TOP_CHECK']) || $_SESSION['TOP_CHECK'] < 1) {
    echo json_encode(array("status" => 'done'));
    return;
Example #27
0
}
$oldgrade = $RESULT->grade;
if (isset($_POST['sum']) && isset($_POST['code'])) {
    $RESULT->setJsonKey('code', $_POST['code']);
    if ($_POST['sum'] != $actual_sum) {
        $_SESSION['error'] = "Your sum did not match";
        header('Location: ' . addSession('index.php'));
        return;
    }
    $val = validate($sanity, $_POST['code']);
    if (is_string($val)) {
        $_SESSION['error'] = $val;
        header('Location: ' . addSession('index.php'));
        return;
    }
    LTIX::gradeSendDueDate(1.0, $oldgrade, $dueDate);
    // Redirect to ourself
    header('Location: ' . addSession('index.php'));
    return;
}
// echo($goodsha);
if ($LINK->grade > 0) {
    echo '<p class="alert alert-info">Your current grade on this assignment is: ' . $LINK->grade * 100.0 . '%</p>' . "\n";
}
if ($dueDate->message) {
    echo '<p style="color:red;">' . $dueDate->message . '</p>' . "\n";
}
?>
<p>
<b>Finding Numbers in a Haystack</b>
<p>
Example #28
0
function webauto_test_passed($grade, $url)
{
    global $displayname;
    global $OUTPUT;
    success_out("Test passed - congratulations");
    if ($displayname === false || !isset($_SESSION['lti'])) {
        line_out('Not setup to return a grade..');
        exit;
    }
    if (!isset($_GET['grade'])) {
        line_out('Dry run - grade of (' . intval($grade * 100) . '%) was not sent.');
        exit;
    }
    gradeUpdateJson(json_encode(array("url" => $url)));
    $debug_log = array();
    $retval = LTIX::gradeSend($grade, false, $debug_log);
    $OUTPUT->dumpDebugArray($debug_log);
    if ($retval == true) {
        $success = "Grade sent to server (" . intval($grade * 100) . "%)";
    } else {
        if (is_string($retval)) {
            $failure = "Grade not sent: " . $retval;
        } else {
            echo "<pre>\n";
            var_dump($retval);
            echo "</pre>\n";
            $failure = "Internal error";
        }
    }
    if (strlen($success) > 0) {
        success_out($success);
        error_log($success);
    } else {
        if (strlen($failure) > 0) {
            error_out($failure);
            error_log($failure);
        } else {
            error_log("No status");
        }
    }
}
Example #29
0
<?php

require_once "../../config.php";
require_once $CFG->dirroot . "/pdo.php";
require_once $CFG->dirroot . "/lib/lms_lib.php";
require_once "peer_util.php";
use Tsugi\Core\LTIX;
// Sanity checks
$LTI = LTIX::requireData();
if (!$USER->instructor) {
    die("Instructor only");
}
if (isset($_POST['doClear'])) {
    session_unset();
    die('session unset');
}
$OUTPUT->header();
$OUTPUT->bodyStart();
$OUTPUT->flashMessages();
$OUTPUT->welcomeUserCourse();
$OUTPUT->togglePre("Session data", safe_var_dump($_SESSION));
?>
<form method="post">
<input type="submit" name="doExit" onclick="location='<?php 
echo addSession('index.php');
?>
'; return false;" value="Exit">
<input type="submit" name="doClear" value="Clear Session (will log out out)">
</form>
<?php 
flush();
Example #30
0
function mailDeleteSubmit($user_id, $assn_json, $note)
{
    global $CFG, $PDOX;
    if (!isset($CFG->maildomain) || $CFG->maildomain === false) {
        return false;
    }
    $LTI = LTIX::requireData();
    $user_row = loadUserInfoBypass($user_id);
    if ($user_row === false) {
        return false;
    }
    $to = $user_row['email'];
    if (strlen($to) < 1 || strpos($to, '@') === false) {
        return false;
    }
    $name = $user_row['displayname'];
    $token = computeMailCheck($user_id);
    $subject = 'From ' . $CFG->servicename . ', Your Peer Graded Entry Has Been Reset';
    $E = "\n";
    if (isset($CFG->maileol)) {
        $E = $CFG->maileol;
    }
    $message = "This is an automated message.  Your peer-graded entry has been reset.{$E}{$E}";
    if (isset($LTI['context_title'])) {
        $message .= 'Course Title: ' . $LTI['context_title'] . $E;
    }
    if (isset($LTI['link_title'])) {
        $message .= 'Assignment: ' . $LTI['link_title'] . $E;
    }
    if (isset($LTI['user_displayname'])) {
        $message .= 'Staff member doing reset: ' . $LTI['user_displayname'] . $E;
    }
    $fixnote = trim($note);
    if (strlen($fixnote) > 0) {
        if ($E != "\n") {
            $fixnote = str_replace("\n", $E, $fixnote);
        }
        $message .= "Notes regarding this action:" . $E . $fixnote . $E;
    }
    $message .= "{$E}You may now re-submit your peer-graded assignment.{$E}";
    $stmt = $PDOX->queryDie("INSERT INTO {$CFG->dbprefix}mail_sent\n            (context_id, link_id, user_to, user_from, subject, body, created_at)\n            VALUES ( :CID, :LID, :UTO, :UFR, :SUB, :BOD, NOW() )", array(":CID" => $LTI['context_id'], ":LID" => $LTI['link_id'], ":UTO" => $user_id, ":UFR" => $LTI['user_id'], ":SUB" => $subject, ":BOD" => $message));
    // echo $to, $subject, $message, $user_id, $token;
    $retval = mailSend($to, $subject, $message, $user_id, $token);
    return $retval;
}