/**
  * Form submission of new/edit api is processed.
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     //get the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     // Save the API Key & Save the Security Key
     if (CRM_Utils_Array::value('api_key', $params)) {
         CRM_Core_BAO_Setting::setItem($params['api_key'], self::MC_SETTING_GROUP, 'api_key');
     }
     $session = CRM_Core_Session::singleton();
     $message = "Api Key has been Saved!";
     $session->setStatus($message, ts('Api Key Saved'), 'success');
     $urlParams = null;
     $session->replaceUserContext(CRM_Utils_System::url('civicrm/mailchimp/apikeyregister', $urlParams));
     try {
         $mcClient = new Mailchimp($params['api_key']);
         $mcHelper = new Mailchimp_Helper($mcClient);
         $details = $mcHelper->accountDetails();
     } catch (Mailchimp_Invalid_ApiKey $e) {
         CRM_Core_Session::setStatus($e->getMessage());
         return FALSE;
     } catch (Mailchimp_HttpError $e) {
         CRM_Core_Session::setStatus($e->getMessage());
         return FALSE;
     }
     $message = "Following is the account information received from API callback:<br/>\n        <table class='mailchimp-table'>\n        <tr><td>Company:</td><td>{$details['contact']['company']}</td></tr>\n        <tr><td>First Name:</td><td>{$details['contact']['fname']}</td></tr>\n        <tr><td>Last Name:</td><td>{$details['contact']['lname']}</td></tr>\n        </table>";
     CRM_Core_Session::setStatus($message);
 }
コード例 #2
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     // Store the submitted values in an array.
     $params = $this->controller->exportValues($this->_name);
     // Save the API Key & Save the Security Key
     if (CRM_Utils_Array::value('api_key', $params) || CRM_Utils_Array::value('security_key', $params)) {
         CRM_Core_BAO_Setting::setItem($params['api_key'], self::MC_SETTING_GROUP, 'api_key');
         CRM_Core_BAO_Setting::setItem($params['security_key'], self::MC_SETTING_GROUP, 'security_key');
         CRM_Core_BAO_Setting::setItem($params['enable_debugging'], self::MC_SETTING_GROUP, 'enable_debugging');
         try {
             $mcClient = new Mailchimp($params['api_key']);
             $mcHelper = new Mailchimp_Helper($mcClient);
             $details = $mcHelper->accountDetails();
         } catch (Mailchimp_Invalid_ApiKey $e) {
             CRM_Core_Session::setStatus($e->getMessage());
             return FALSE;
         } catch (Mailchimp_HttpError $e) {
             CRM_Core_Session::setStatus($e->getMessage());
             return FALSE;
         }
         $message = "Following is the account information received from API callback:<br/>\n        <table class='mailchimp-table'>\n        <tr><td>Company:</td><td>{$details['contact']['company']}</td></tr>\n        <tr><td>First Name:</td><td>{$details['contact']['fname']}</td></tr>\n        <tr><td>Last Name:</td><td>{$details['contact']['lname']}</td></tr>\n        </table>";
         CRM_Core_Session::setStatus($message);
     }
 }