You are here

function kaltura_settings_form in Kaltura 6

Same name and namespace in other branches
  1. 5 includes/kaltura.admin.inc \kaltura_settings_form()
  2. 6.2 includes/kaltura.admin.inc \kaltura_settings_form()
  3. 7.2 includes/kaltura.admin.inc \kaltura_settings_form()
2 string references to 'kaltura_settings_form'
kaltura_form_alter in includes/kaltura.admin.inc
kaltura_menu in ./kaltura.module

File

includes/kaltura.admin.inc, line 166

Code

function kaltura_settings_form() {
  global $base_url;
  if (variable_get('kaltura_partner_id', '') != '') {
    $notification_settings = kaltura_notifications_settings_form();
    $form['kaltura_notification_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Kaltura to Drupal Notification Settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    foreach ($notification_settings as $name => $form_element) {
      $form['kaltura_notification_settings'][$name] = $form_element;
    }
    $form['kaltura_server_status'] = array(
      '#type' => 'fieldset',
      '#title' => t('Server Status'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    list($admin_session_status, $admin_session_error) = kaltura_check_server_status($admin = 1);
    list($normal_session_status, $normal_session_error) = kaltura_check_server_status($admin = 0);
    $status_class = $admin_session_status && $normal_session_status ? 'ok' : 'bad';
    $session_status = $admin_session_status && $normal_session_status ? 'OK' : 'ERROR';
    $error = ' kaltura_error: ';
    if ($admin_session_error) {
      $error .= '<br />admin session: ' . $admin_session_error;
      $error_status = TRUE;
    }
    if ($normal_session_error) {
      $error .= '<br />normal session: ' . $normal_session_error;
      $error_status = TRUE;
    }
    $form['kaltura_server_status']['kaltura_Admin_test_server'] = array(
      '#type' => 'item',
      '#title' => t('Drupal to Kaltura Session Test'),
      '#prefix' => '<div class="kaltura_status_' . $status_class . '">',
      '#value' => 'Session status: ' . $session_status . ($error_status ? $error : ''),
      '#suffix' => '</div>',
    );
    if (kaltura_variable_get_real('kaltura_notification_type', 0) == 1) {
      list($status, $text) = kaltura_test_notification_config();
      $prefix = '<div class="kaltura_status_' . ($status ? 'ok' : 'bad') . '">';
      $form['kaltura_server_status']['kaltura_notification_status'] = array(
        '#type' => 'item',
        '#title' => t('Kaltura to Drupal Notification Status'),
        '#prefix' => $prefix,
        '#value' => $text,
        '#suffix' => '</div>',
      );
    }
    list($status, $text) = kaltura_test_cron_job_status();
    $prefix = '<div class="kaltura_status_' . ($status ? 'ok' : 'bad') . '">';
    $form['kaltura_server_status']['kaltura_cron_job_status'] = array(
      '#type' => 'item',
      '#title' => t('Cron-Job Status'),
      '#prefix' => $prefix,
      '#value' => $text,
      '#suffix' => '</div>',
    );
    list($status, $text) = kaltura_test_crossdomain();
    $prefix = '<div class="kaltura_status_' . ($status ? 'ok' : 'bad') . '">';
    $form['kaltura_server_status']['kaltura_crossdomain_status'] = array(
      '#type' => 'item',
      '#title' => t('CrossDomain.xml Status'),
      '#prefix' => $prefix,
      '#value' => $text,
      '#suffix' => '</div>',
    );
  }
  $register_visible = FALSE;
  if ($_REQUEST['partner_name'] && $_REQUEST['op'] == 'Complete Installation') {
    if ($_REQUEST['kaltura_agree_terms'] == 1) {
      register_kaltura_partner();
    }
    else {
      drupal_set_message('You must agree to the terms of use', 'error');
    }
  }
  if ($_REQUEST['op'] == 'Complete Installation' && $_REQUEST['kaltura_partner_id']) {
    list($pid, $subpid, $url2, $secret, $admin_secret) = kaltura_get_partner_details($_REQUEST['kaltura_partner_id'], $_REQUEST['cms_email'], $_REQUEST['cms_password']);
    if ($pid) {
      variable_set('kaltura_partner_id', $pid);
      variable_set('kaltura_subp_id', $subpid);
      variable_set('kaltura_secret', $secret);
      variable_set('kaltura_admin_secret', $admin_secret);
      variable_set('kaltura_partner_url2', str_replace('/?q=kaltura/notification_handler', '', $url2));
      variable_set('kaltura_partner_cms_email', $_REQUEST['cms_email']);
      variable_set('kaltura_partner_cms_password', $_REQUEST['cms_password']);
      variable_set('kaltura_server_url', KalturaHelpers::getKalturaServerUrl());
      drupal_set_message('Your partner details were imported successfully. please check the ' . l('notification settings', 'admin/settings/kaltura/general/notifications'));
      drupal_set_message('You can ' . l('import Kaltura Media from your existing partner', 'admin/settings/kaltura/import'));
      kaltura_create_widgets_for_partner($pid, $secret);
      kaltura_update_kaltura_partner(2, $url2);
      drupal_goto('admin/settings/kaltura/general');
    }
    else {
      drupal_set_message('Couldn\'t import partner details.<br />' . print_r($subpid, TRUE) . $subpid['code'] . ': ' . $subpid['desc'], 'error');
    }
  }
  if (variable_get('kaltura_partner_id', '') == '') {
    $register_visible = TRUE;
    global $user;
    $information_text = 'Once you complete the form below and click "Complete installation", ' . 'the All in One Video Module will be fully installed and ready to use.<br />';
    $registered = '<br /><a href="#" onclick="switch_to_exist_partner();return false;">Click here if you already have a Partner ID</a>';
    $not_registered = 'If you are not registered as a Kaltura partner, and would like to register ' . '<input type="button" onclick="switch_to_register();" value="Click Here" />';
    $form['kaltura_settings_information'] = array(
      '#value' => t($information_text) . $registered,
    );
    if ($_GET['register'] !== 'no') {
      drupal_set_title('All in One Video Module by Kaltura Installation');

      // registration form
      $showing_reg = TRUE;
      $form['kaltura_registration'] = array(
        '#type' => 'fieldset',
        '#title' => t('Registration'),
        '#collapsible' => FALSE,
        '#collapsed' => FALSE,
      );
      $form['kaltura_registration']['partner_name'] = array(
        '#type' => 'textfield',
        '#title' => t('Website Name'),
        '#default_value' => variable_get('site_name', ''),
        '#size' => 100,
        '#maxlength' => 256,
      );
      $form['kaltura_registration']['partner_url1'] = array(
        '#type' => 'hidden',
        '#title' => t('Your Website Address'),
        '#default_value' => $base_url,
        '#size' => 100,
        '#maxlength' => 1024,
      );
      $form['kaltura_registration']['partner_url2'] = array(
        '#type' => 'hidden',
        '#title' => t('URL 2'),
        '#default_value' => $base_url,
        '#maxlength' => 1024,
      );
      $form['kaltura_registration']['partner_adminName'] = array(
        '#type' => 'textfield',
        '#title' => t('Administrator Name'),
        '#default_value' => $user->name,
        '#size' => 100,
        '#maxlength' => 50,
      );
      $form['kaltura_registration']['partner_adminEmail'] = array(
        '#type' => 'textfield',
        '#title' => t('Administrator Email'),
        '#default_value' => $user->mail,
        '#size' => 100,
        '#maxlength' => 100,
      );
      $categories = new KalturaContentCategories();
      $form['kaltura_registration']['kaltura_content_categories'] = array(
        '#type' => 'select',
        '#title' => t('Content Categories'),
        '#multiple' => TRUE,
        '#size' => 8,
        '#options' => $categories->categories,
      );
      $form['kaltura_registration']['kaltura_adult_content'] = array(
        '#type' => 'radios',
        '#title' => t('Do you plan to display adult content?'),
        '#options' => array(
          1 => 'Yes',
          0 => 'No',
        ),
        '#default_value' => variable_get('kaltura_adult_content', 0) == 0 ? 0 : 1,
      );
      $form['kaltura_registration']['partner_description'] = array(
        //'#type' => 'textarea',
        '#type' => 'hidden',
        '#title' => t('Partner Description'),
        '#default_value' => 'Drupal module|' . VERSION,
      );
      $form['kaltura_registration']['cms_password'] = array(
        '#type' => 'hidden',
        '#title' => t('CMS password'),
        '#default_value' => kaltura_generate_cms_password(),
        '#size' => 20,
        '#maxlength' => 60,
      );
      $form['kaltura_registration']['kaltura_agree_terms'] = array(
        '#type' => 'checkbox',
        '#title' => 'I agree to comply with the <a href="http://www.kaltura.com/index.php/corp/tandc" target="_blank">Kaltura Terms of Use</a>',
        '#options' => 'Agree',
        '#required' => TRUE,
      );
      $form_state['storage']['submit'] = 'Register';
      $form['kaltura_registration']['buttons']['register'] = array(
        '#type' => 'button',
        '#title' => 'Complete Installation',
        '#value' => 'Complete Installation',
        '#default_value' => 'Complete Installation',
        '#weight' => 40,
      );
    }
  }
  if ($_GET['register'] === 'no' || !$showing_reg && !isset($_GET['register'])) {

    // normal settings form
    if (variable_get('kaltura_partner_id', '') == '') {
      drupal_set_title('All in One Video Module by Kaltura Installation');
      $forgot_link_attributes = array(
        'attributes' => array(
          'target' => '_blank',
        ),
      );
      $information_text = 'Please enter your Kaltura email &amp; password';
      $information_text .= '<br />' . l('forgot password', 'http://www.kaltura.com/index.php/cms/login', $forgot_link_attributes);
      $form['kaltura_settings_information']['#value'] = $information_text;
    }
    $form['kaltura_partner_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Partner Info'),
      '#collapsible' => $_GET['register'] === 'no' ? FALSE : TRUE,
      '#collapsed' => $_GET['register'] === 'no' ? FALSE : TRUE,
    );

    /*
    $form['kaltura_partner_settings']['kaltura_exitss_switch'] = array(
      '#value' => $not_registered,
    );
    */
    $form['kaltura_partner_settings']['kaltura_partner_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Partner ID'),
      '#default_value' => variable_get('kaltura_partner_id', ''),
      '#size' => 20,
      '#maxlength' => 10,
    );
    $form['kaltura_partner_settings']['cms_email'] = array(
      '#type' => 'textfield',
      '#title' => t('Email'),
      '#default_value' => variable_get('kaltura_partner_cms_email', ''),
    );
    $form['kaltura_partner_settings']['cms_password'] = array(
      '#type' => 'textfield',
      '#title' => t('Password'),
      '#default_value' => variable_get('kaltura_partner_cms_password', ''),
    );
    if (variable_get('kaltura_partner_id', '') == '') {
      $form_state['storage']['submit'] = 'ImportPartner';
      $form['kaltura_registration']['buttons']['import_partner'] = array(
        '#type' => 'button',
        '#title' => 'Complete Installation',
        '#value' => 'Complete Installation',
        '#default_value' => 'Complete Installation',
        '#weight' => 40,
      );
    }
    $form['kaltura_partner_settings']['kaltura_subp_id'] = array(
      '#type' => 'hidden',
      '#title' => t('Kaltura Sub-Partner Id'),
      '#default_value' => variable_get('kaltura_subp_id', ''),
      '#size' => 20,
      '#maxlength' => 10,
    );
    if (variable_get('kaltura_local_registration', 0) != 1 || 1) {
      $form['kaltura_partner_settings']['kaltura_secret'] = array(
        '#type' => 'hidden',
        '#title' => t('Kaltura Secret'),
        '#default_value' => variable_get('kaltura_secret', ''),
        '#size' => 60,
        '#maxlength' => 64,
      );
      $form['kaltura_partner_settings']['kaltura_admin_secret'] = array(
        '#type' => 'hidden',
        '#title' => t('Kaltura Admin Secret'),
        '#default_value' => variable_get('kaltura_admin_secret', ''),
        '#size' => 60,
        '#maxlength' => 64,
      );
    }
    $form['kaltura_partner_settings']['kaltura_server_url'] = array(
      '#type' => 'hidden',
      '#title' => t('Kaltura Server URL'),
      '#default_value' => variable_get('kaltura_server_url', KalturaHelpers::getKalturaServerUrl()),
      '#size' => 100,
      '#maxlength' => 64,
    );
  }
  $form['kaltura_help_message'] = array(
    '#type' => 'item',
    '#value' => t('Please feel free to ') . l('contact us', 'http://corp.kaltura.com/support/form/project/16', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )) . t(' with any questions.'),
  );
  return system_settings_form($form);
}