/**
  * Save this user to WebEx.
  *
  * @return bool    True if auth succeeded, false if failed.
  * @throws invalid_response_exception for unexpected WebEx response.
  * @throws coding_exception.
  */
 public function save_to_webex()
 {
     $webex = new webex();
     if (isset($this->webexuserid)) {
         // The user has already been saved to WebEx, update.
         $xml = xml_gen::update_user($this);
         $response = $webex->get_response($xml);
         if ($response !== false) {
             return true;
         } else {
             return false;
         }
     } else {
         // Creating a new user.
         $this->schedulingpermission = get_config('webexactivity', 'apiusername');
         $xml = xml_gen::create_user($this);
         try {
             $response = $webex->get_response($xml);
         } catch (exception\webex_xml_exception $e) {
             $response = false;
         } catch (exception\webex_user_collision $e) {
             // Expection for username or email already exists.
             if ($this->update_from_webex()) {
                 return true;
             }
             // Can't use this user.
             throw $e;
         }
         if ($response) {
             if (isset($response['use:userId']['0']['#'])) {
                 $this->webexuserid = $response['use:userId']['0']['#'];
                 return true;
             } else {
                 throw new \invalid_response_exception('Unexpected WebEx response when creating user');
             }
         } else {
             $errors = $webex->get_latest_errors();
             // Failure creating user. Check to see if exists.
             if (!isset($errors['exception'])) {
                 throw new \invalid_response_exception('No errors found when creating users. Error expected.');
             }
             $exception = $errors['exception'];
             throw new \coding_exception('WebEx exception ' . $exception . ' when creating new user.');
         }
         throw new \coding_exception('Unknown error when creating new user.');
     }
 }