* @author David Zaharee <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/config.php'; require_once dirname(__FILE__) . '/lib.php'; require_login(0, false); # make sure user is instructor or helper $user = $DB->get_record('block_helpmenow_user', array('userid' => $USER->id)); $helper = $DB->get_records('block_helpmenow_helper', array('userid' => $USER->id)); if (!$user and !$helper) { helpmenow_fatal_error('You do not have permission to view this page.'); } # make sure we've got a gotomeeting user2plugin record with a token $token_url = new moodle_url("{$CFG->wwwroot}/blocks/helpmenow/plugins/gotomeeting/token.php"); $token_url->param('redirect', qualified_me()); $token_url = $token_url->out(); if ($record = $DB->get_record('block_helpmenow_user2plugin', array('userid' => $USER->id, 'plugin' => 'gotomeeting'))) { $user2plugin = new helpmenow_user2plugin_gotomeeting(null, $record); } else { $user2plugin = new helpmenow_user2plugin_gotomeeting(); $user2plugin->userid = $USER->id; $user2plugin->insert(); redirect($token_url); } # check to see if the oauth token has expired if ($user2plugin->token_expiration < time()) { redirect($token_url); } $user2plugin->create_meeting(); $user2plugin->update(); redirect($user2plugin->join_url);
$ch = curl_init($citrix_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $oauth = json_decode(curl_exec($ch)); $responsecode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($admin) { $userid = get_admin()->id; } else { $userid = $USER->id; } # save the reponse to user2plugin record if (!($record = $DB->get_record('block_helpmenow_user2plugin', array('userid' => $userid, 'plugin' => 'gotomeeting')))) { $user2plugin = new helpmenow_user2plugin_gotomeeting(); $user2plugin->userid = $userid; $user2plugin->insert(); } else { $user2plugin = new helpmenow_user2plugin_gotomeeting(null, $record); } $user2plugin->access_token = $oauth->access_token; $user2plugin->token_expiration = $oauth->expires_in + time(); $user2plugin->refresh_token = $oauth->refresh_token; $user2plugin->update(); redirect($redirect); } $title = 'Token'; # todo: language string $nav = array(array('name' => $title)); foreach ($nav as $node) { $PAGE->navbar->add($node['name'], isset($node['link']) ? $node['link'] : null); } $PAGE->set_title($title); $PAGE->set_heading($title);
public static function on_logout() { global $CFG, $USER, $DB; $user2plugin = helpmenow_user2plugin_gotomeeting::get_user2plugin(); # see if the user is still logged in to a different queue/office $sql = "\n SELECT 1\n WHERE EXISTS (\n SELECT 1\n FROM {block_helpmenow_helper}\n WHERE userid = {$USER->id}\n AND isloggedin <> 0\n )\n OR EXISTS (\n SELECT 1\n FROM {block_helpmenow_user}\n WHERE userid = {$USER->id}\n AND isloggedin <> 0\n )\n "; # if they aren't, delete the meeting info from user2plugin record and update the db if (!$DB->record_exists_sql($sql)) { foreach (array('join_url', 'max_participants', 'unique_meetingid', 'meetingid') as $attribute) { $user2plugin->{$attribute} = null; } return $user2plugin->update(); } return true; }