You are here

function vkxp_admin_main_settings_submit in VK CrossPoster 6.2

Same name and namespace in other branches
  1. 6 vkxp.admin.inc \vkxp_admin_main_settings_submit()
  2. 7 vkxp.admin.inc \vkxp_admin_main_settings_submit()

Submit function for vkxp main settings form.

File

./vkxp.admin.inc, line 119
Contains vkxp settings forms.

Code

function vkxp_admin_main_settings_submit($form, &$form_state) {
  $values = $form_state['values'];

  // Save values
  variable_set('vkxp_enable', $values['vkxp_enable']);
  variable_set('vkxp_group_id', trim($values['vkxp_group_id']));
  variable_set('vkxp_wall_owner', $values['vkxp_wall_owner']);
  variable_set('vkxp_enabled_default', $values['vkxp_enabled_default']);
  variable_set('vkxp_official', $values['vkxp_official']);
  variable_set('vkxp_add_link', $values['vkxp_add_link']);

  // If application id or application secret was changed we should get new access token.
  $app_id_changed = variable_get('vkxp_app_id', 0) != $values['vkxp_app_id'];
  $secret_changed = variable_get('vkxp_app_secret', 0) != $values['vkxp_app_secret'];
  $reset_clicked = $values['op'] == $form['reset']['#value'];
  if ($app_id_changed || $secret_changed || $reset_clicked) {
    variable_set('vkxp_app_id', trim($values['vkxp_app_id']));
    variable_set('vkxp_app_secret', trim($values['vkxp_app_secret']));
    $params = array();
    $params['client_id'] = trim($values['vkxp_app_id']);
    $params['scope'] = 'wall,groups,photos,offline';
    $params['display'] = 'page';
    $params['redirect_uri'] = url('admin/settings/vkxp/main', array(
      'absolute' => TRUE,
    ));
    $params['response_type'] = 'code';
    $data = http_build_query($params, '', '&');
    $url = 'http://api.vkontakte.ru/oauth/authorize?' . $data;
    drupal_goto($url);
  }
  drupal_set_message(t('The configuration options have been saved.'));
}