/**
  * Returns the webex user that hosts this meeting.
  *
  * @return bool|user    The WebEx user. False on failure.
  */
 public function get_host_webex_user()
 {
     global $USER;
     $webexuser = false;
     if (isset($this->hostwebexid)) {
         try {
             // Try and load the user for this meetings user.
             $webexuser = \mod_webexactivity\user::load_webex_id($this->hostwebexid);
         } catch (\coding_exception $e) {
             $webexuser = false;
         }
     }
     // If we haven't set it, try and set it to the current user.
     if (!$webexuser) {
         $webexuser = \mod_webexactivity\user::load_for_user($USER);
     }
     return $webexuser;
 }
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once $CFG->libdir . '/adminlib.php';
admin_externalpage_setup('modwebexactivityusers');
$pageurl = new moodle_url('/mod/webexactivity/admin_users.php');
$action = optional_param('action', false, PARAM_ALPHA);
switch ($action) {
    case 'login':
        // First log the user out (in case they are logged in, then bring back to logintrue.
        $webexid = required_param('webexid', PARAM_ALPHAEXT);
        $returnurl = new moodle_url($pageurl, array('action' => 'logintrue', 'webexid' => $webexid));
        redirect(\mod_webexactivity\user::get_logout_url($returnurl->out(false)));
        break;
    case 'logintrue':
        // Actually log the user in.
        $webexid = required_param('webexid', PARAM_ALPHAEXT);
        $webexuser = \mod_webexactivity\user::load_webex_id($webexid);
        redirect($webexuser->get_login_url());
        break;
}
// Setup the table for output.
$table = new \mod_webexactivity\admin_users_table('webexactivityadminrecordingstable');
$table->define_baseurl($pageurl);
$table->set_sql('*', '{webexactivity_user}', '1=1', array());
$table->define_columns(array('firstname', 'lastname', 'email', 'webexid', 'login'));
$table->define_headers(array(get_string('firstname'), get_string('lastname'), get_string('email'), get_string('webexid', 'webexactivity'), ''));
$table->no_sorting('login');
echo $OUTPUT->header();
// Output the table.
$table->out(50, false);
echo $OUTPUT->footer();