public function refreshAPIKey($type)
 {
     global $settings;
     if ($this->keyStatus == 1 and $this->accessMask == MINIMUM_API and $this->expires == 'No Expiration' and $this->keyType == 'Account') {
         $update = $this->updateAPIKey();
         if ($update) {
             if ($settings->getSlackIntegration() and $settings->getSlackAPINotifications() and $type == 'new') {
                 sendComplexSlackNotification($settings->getSlackAuthToken(), $settings->getGroupTicker() . ' Auth Notifications', $settings->getSlackAPIChannel(), 'New API Key submitted by ' . User::fetchUserName($this->uid) . '.', 'aura', 'chat.postMessage');
             }
             $character_array = array();
             foreach ($this->getCharacters() as $character) {
                 $character_array[$character['characterID']] = $character['characterID'];
                 $char = new Character($character['characterID'], $this->keyID, $this->vcode, $this->accessMask, $this->db, $this->uid);
                 if ($char->getExistance() or $char->getExistance() == FALSE) {
                     $char->updateCharacterInfo();
                     $char->updateCharacterSkills();
                 }
             }
             $stmt = $this->db->prepare('UPDATE core_cron SET cron_updated = 1 WHERE api_keyID = ?');
             $stmt->execute(array($this->keyID));
             $this->removeOrphanedCharacter($this->keyID, $this->uid, $character_array);
             return TRUE;
         }
     } elseif ($this->keyStatus != 1 and $type == 'new') {
         if ($settings->getSlackIntegration() and $settings->getSlackAPINotifications()) {
             sendComplexSlackNotification($settings->getSlackAuthToken(), $settings->getGroupTicker() . ' Auth Notifications', $settings->getSlackAPIChannel(), 'API Key submitted by ' . User::fetchUserName($this->uid) . ' has been rejected as it is invalid.', 'aura', 'chat.postMessage');
         }
         setAlert('danger', 'The API Key Is Invalid', 'The API Key provided is invalid and cannot be used. Please create a new API key, and ensure you have copied the keyID and verification code correctly.');
     } elseif (!($this->accessMask == MINIMUM_API) and $this->getKeyStatus() == 1 and $type == "new") {
         if ($settings->getSlackIntegration() and $settings->getSlackAPINotifications()) {
             sendComplexSlackNotification($settings->getSlackAuthToken(), $settings->getGroupTicker() . ' Auth Notifications', $settings->getSlackAPIChannel(), 'API Key submitted by ' . User::fetchUserName($this->uid) . ' has been rejected due to an incorrect access mask.', 'aura', 'chat.postMessage');
         }
         setAlert('danger', 'The API Key Does Not Meet Minimum Requirements', 'The required minimum Access Mask for API keys is ' . MINIMUM_API . '. Please create a new key using the Create Key link.');
     } elseif ($this->expires != 'No Expiration' and $type == "new") {
         if ($settings->getSlackIntegration() and $settings->getSlackAPINotifications()) {
             sendComplexSlackNotification($settings->getSlackAuthToken(), $settings->getGroupTicker() . ' Auth Notifications', $settings->getSlackAPIChannel(), 'API Key submitted by ' . User::fetchUserName($this->uid) . ' has been rejected because it has an expiration.', 'aura', 'chat.postMessage');
         }
         setAlert('danger', 'The API Key Expires', 'The provided API Key has an expiration set. Please create a new key using the Create Key link and ensure you select the No Expiration checkbox.');
     } elseif ($this->keyType != 'Account' and $type == "new") {
         if ($settings->getSlackIntegration() and $settings->getSlackAPINotifications()) {
             sendComplexSlackNotification($settings->getSlackAuthToken(), $settings->getGroupTicker() . ' Auth Notifications', $settings->getSlackAPIChannel(), 'API Key submitted by ' . User::fetchUserName($this->uid) . ' has been rejected because it is a single character key.', 'aura', 'chat.postMessage');
         }
         setAlert('danger', 'The API Key Provided is Single-Character', 'All API Keys must be account-wide. Please create a new key using the Create Key link, and do not change the key from an Account Key to a Single Character key.');
     }
 }