You are here

function _salesforce_admin_list in Salesforce Suite 5

helper functions

1 call to _salesforce_admin_list()
salesforce_admin_page in ./salesforce.module
admin page for viewing the salesforce_logs table

File

./salesforce.module, line 430
Original Creator, Maintainer & Developer: Steve McKenzie (http://drupal.org/user/45890) Drupal and Salesforce.com (mainly only working with contacts / leads but can be extended to do anything the salesforce API version 6 can do) Current…

Code

function _salesforce_admin_list($op) {
  $sf = 'https://na1.salesforce.com/';
  if ($op == 'lead' || $op == 'contact') {
    $result = db_query("SELECT s.uid FROM {salesforce_users} s WHERE %s != ''", 's.' . $op . '_id');
    if (db_num_rows($result) > 0) {
      $cols = array(
        array(
          'data' => t('User'),
          'class' => 'user',
        ),
        array(
          'data' => t('Name'),
        ),
        array(
          'data' => t('%i', array(
            '%i' => ucfirst($op) . ' ID',
          )),
          'class' => 'id',
        ),
      );
      if ($op == 'contact') {
        $cols[] = array(
          'data' => t('Account ID', array(
            '%i' => ucfirst($op),
          )),
          'class' => 'id',
        );
      }
      while ($row = db_fetch_object($result)) {
        if ($op == 'contact') {

          // we do this incase we don't have a cached account id
          salesforce_account_select(user_load(array(
            'uid' => $row->uid,
          )));
        }
        $account = user_load(array(
          'uid' => $row->uid,
        ));

        // remove the extra 3 chars that are not used in this case
        $link = $sf . substr($account->salesforce[$op . '_id'], 0, strlen($account->salesforce[$op . '_id']) - 3);
        $rows[$row->uid] = array(
          theme('username', $account),
          $account->first_name . ' ' . $account->last_name,
          l($account->salesforce[$op . '_id'], $link),
        );
        if ($op == 'contact') {
          if ($account->salesforce['account_id']) {
            $account_link = $sf . substr($account->salesforce['account_id'], 0, strlen($account->salesforce['account_id']) - 3);
            $account_label = l($account->salesforce['account_id'], $account_link);
          }
          else {
            $account_label = t('N/A');
          }
          $rows[$row->uid][] = $account_label;
        }
      }
      $output .= '<p>' . t('%type in salesforce', array(
        '%type' => ucfirst($op) . 's',
      )) . '</p>' . "\n";
      $output .= theme('table', $cols, $rows, array(
        'class' => 'salesforce_' . $op . '_list',
      ));
    }
    else {
      drupal_set_message(t('currently no %op', array(
        '%op' => $op . 's',
      )));
    }
  }
  return $output;
}