Example #1
0
 public static function handleRedirectReturn($data = false)
 {
     if (isset($data['error'])) {
         return 'There was an error. (general) Please try again.';
     } else {
         $connections = CASHSystem::getSystemSettings('system_connections');
         require_once CASH_PLATFORM_ROOT . '/lib/oauth2/OAuth2Client.php';
         require_once CASH_PLATFORM_ROOT . '/lib/oauth2/OAuth2Exception.php';
         require_once CASH_PLATFORM_ROOT . '/lib/mailchimp/MC_OAuth2Client.php';
         $oauth_options = array('redirect_uri' => $connections['com.mailchimp']['redirect_uri'], 'client_id' => $connections['com.mailchimp']['client_id'], 'client_secret' => $connections['com.mailchimp']['client_secret'], 'code' => $data['code']);
         $client = new MC_OAuth2Client($oauth_options);
         $session = $client->getSession();
         if ($session) {
             require_once CASH_PLATFORM_ROOT . '/lib/mailchimp/MailChimp.class.php';
             $cn = new MC_OAuth2Client($oauth_options);
             $cn->setSession($session, false);
             $odata = $cn->api('metadata', 'GET');
             $access_token = $session['access_token'];
             $api_key = $session['access_token'] . '-' . $odata['dc'];
             $api = new MailChimp($api_key);
             $lists = $api->call('lists/list');
             $return_markup = '<h4>Connect to MailChimp</h4>' . '<p>Now just choose a list and save the connection.</p>' . '<form accept-charset="UTF-8" method="post" action="">' . '<input type="hidden" name="dosettingsadd" value="makeitso" />' . '<input id="connection_name_input" type="hidden" name="settings_name" value="(MailChimp list)" />' . '<input type="hidden" name="settings_type" value="com.mailchimp" />' . '<input type="hidden" name="key" value="' . $api_key . '" />' . '<label for="list">Choose a list to connect to:</label>' . '<select id="list_select" name="list">';
             $selected = ' selected="selected"';
             $list_name = false;
             foreach ($lists['data'] as $list) {
                 if ($selected) {
                     $list_name = $list['name'];
                 }
                 $return_markup .= '<option value="' . $list['id'] . '"' . $selected . '>' . $list['name'] . '</option>';
                 $selected = false;
             }
             $return_markup .= '</select><br /><br />' . '<div><input class="button" type="submit" value="Add The Connection" /></div>' . '</form>' . '<script type="text/javascript">' . '$("#connection_name_input").val("' . $list_name . ' (MailChimp)");' . '$("#list_select").change(function() {' . '	var newvalue = this.options[this.selectedIndex].text + " (MailChimp)";' . '	$("#connection_name_input").val(newvalue);' . '});' . '</script>';
             return $return_markup;
         } else {
             return 'There was an error. (session) Please try again.';
         }
     }
 }