示例#1
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/constants.inc.php';
use smtech\CanvasManagement\Toolbox;
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider;
use Battis\DataUtilities;
@session_start();
// TODO suppressing warnings is wrong
/* prepare the toolbox */
if (empty($_SESSION[Toolbox::class])) {
    $_SESSION[Toolbox::class] = Toolbox::fromConfiguration(CONFIG_FILE);
}
$toolbox =& $_SESSION[Toolbox::class];
/* set the Tool Consumer's instance URL, if present */
if (empty($_SESSION[CANVAS_INSTANCE_URL])) {
    if (!empty($_SESSION[ToolProvider::class]['canvas']['api_domain'])) {
        $_SESSION[CANVAS_INSTANCE_URL] = 'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain'];
    } else {
        $_SESSION[CANVAS_INSTANCE_URL] = $toolbox->config('TOOL_CANVAS_API')['url'];
    }
}
/* cache per-instance */
$toolbox->cache_pushKey(parse_url($_SESSION[CANVAS_INSTANCE_URL], PHP_URL_HOST));
/* Configure smarty templating */
/* FIXME this is sometimes superfluous overhead (e.g. action=config) */
$toolbox->smarty_prependTemplateDir(__DIR__ . '/templates', basename(__DIR__));
$toolbox->getSmarty()->addStylesheet(DataUtilities::URLfromPath(__DIR__ . '/css/canvas-management.css'), basename(__DIR__));
$toolbox->smarty_assign(['title' => $toolbox->config('TOOL_NAME'), 'category' => DataUtilities::titleCase(preg_replace('/[\\-_]+/', ' ', basename(__DIR__))), 'APP_URL' => $toolbox->config('APP_URL'), 'CANVAS_INSTANCE_URL' => $_SESSION[CANVAS_INSTANCE_URL], 'navbarActive' => basename(dirname($_SERVER['REQUEST_URI']))]);
示例#2
0
    $toolbox->lti_authenticate();
    exit;
}
/* if authenticated LTI launch, redirect to appropriate placement view */
if (!empty($_SESSION[ToolProvider::class]['canvas']['account_id'])) {
    $toolbox->smarty_display('home.tpl');
    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 make (sometimes dramatic) updates to your course and user data via administrative scripts. 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 */