예제 #1
0
    $_SESSION[ACCOUNT_ID] = $_SESSION[ToolProvider::class]['canvas']['account_id'];
    header("Location: account/");
    exit;
} elseif (!empty($_SESSION[ToolProvider::class]['canvas']['course_id'])) {
    $_SESSION[COURSE_ID] = $_SESSION[ToolProvider::class]['canvas']['course_id'];
    header('Location: course/');
    exit;
    /* if not authenticated, default to showing credentials */
} else {
    $action = empty($action) ? ACTION_CONFIG : $action;
}
/* process any actions */
switch ($action) {
    /* reset cached install data from config file */
    case ACTION_INSTALL:
        $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true);
        $toolbox =& $_SESSION['toolbox'];
        /* test to see if we can connect to the API */
        try {
            $toolbox->getAPI();
        } catch (ConfigurationException $e) {
            /* if there isn't an API token in config.xml, are there OAuth credentials? */
            if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) {
                $toolbox->interactiveGetAccessToken('This tool requires access to the Canvas APIs by an administrative user. ' . 'This API access is used to query student analytics data that is presented on ' . 'the Advisor Dashboard. Please enter the URL of your Canvas instance below ' . '(e.g. <code>https://canvas.instructure.com</code> -- the URL that you would ' . 'enter to log in to Canvas). If you are not already logged in, you will be asked ' . 'to log in. After logging in, you will be asked to authorize this tool.</p>' . '<p>If you are already logged, but <em>not</em> logged in as an administrative user, ' . 'please log out now, so that you may log in as administrative user to authorize this tool.');
                exit;
            } else {
                /* no (understandable) API credentials available -- doh! */
                throw $e;
            }
        }
        /* finish by opening consumers control panel */
예제 #2
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
use smtech\AdvisorDashboard\Toolbox;
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider;
use Battis\DataUtilities;
define('CONFIG_FILE', __DIR__ . '/config.xml');
define('CANVAS_INSTANCE_URL', 'canvas_instance_url');
define('ACCOUNT_ID', 'account_id');
define('COURSE_ID', 'course_id');
@session_start();
// TODO I don't feel good about suppressing warnings
/* prepare the toolbox */
if (empty($_SESSION[Toolbox::class])) {
    $_SESSION[Toolbox::class] =& Toolbox::fromConfiguration(CONFIG_FILE);
}
$toolbox =& $_SESSION[Toolbox::class];
$toolbox->smarty_assign(['category' => DataUtilities::titleCase(preg_replace('/[\\-_]+/', ' ', basename(__DIR__)))]);
/* set the Tool Consumer's instance URL, if present */
if (empty($_SESSION[CANVAS_INSTANCE_URL]) && !empty($_SESSION[ToolProvider::class]['canvas']['api_domain'])) {
    $_SESSION[CANVAS_INSTANCE_URL] = 'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain'];
}