$context_id = $context->info['context_id'];
 //echo $context_id;
 //these are used to update db by get_token_domain
 $isAdmin = $context->isAdministrator();
 setcookie("context", $context_id, 0, '/');
 setcookie("isAdmin", $isAdmin, 0, '/');
 setcookie("lti_url", "https://apps.ats.udel.edu" . $_SERVER['PHP_SELF'], 0, '/');
 //changelog - get token from token table
 $shared = array_key_exists('custom_shared', $context->info);
 //this is a Haywood J token. He is an instructor in Becky Test
 //if($asinstructor)$_SESSION['token']='25~18Dk6lWaa44bnPTWe1xbRydhRJ9zKOc3g3mfbqazxPpgw7MOJ4qGCSRGjJSKQewq';
 if ($_SESSION['token']) {
     //use whatever I've already got from previous trips
     $api = new CanvasAPI($_SESSION['token'], $domain);
     $valid = $api->ready;
     $tokenstatus = "found in session" . $api->status . "," . $api->is_valid_token();
 } else {
     if (!$_SESSION['temptoken']) {
         /*new plan, use an admin token unless I've set the shared flag*/
         if ($isAdmin && !$shared) {
             //only an admin can create an admin token, and only if we're not sharing
             if ($domain == "udel.instructure.com") {
                 setcookie('tokenquery', 'none', 0, '/');
             } else {
                 setcookie('tokenquery', "insert into tokens (domain, context, token) values ('" . $domain . "', '" . $domain . "', '%s') on duplicate key update token=values(token)", 0, '/');
             }
         } else {
             if ($context->isInstructor()) {
                 //only instructors can create context tokens, but an admin can be an instructor
                 setcookie('tokenquery', "insert into tokens (domain, context, token) values ('" . $domain . "', '" . $context_id . "', '%s') on duplicate key update token=values(token)", 0, '/');
             }