You are here

function merci_preprocess_merci_printable_contract in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

Same name and namespace in other branches
  1. 6.2 modules/merci_printable_contract/merci_printable_contract.module \merci_preprocess_merci_printable_contract()
  2. 7.2 modules/merci_printable_contract/merci_printable_contract.module \merci_preprocess_merci_printable_contract()

File

modules/merci_printable_contract/merci_printable_contract.module, line 125
merci_printable_contract functions

Code

function merci_preprocess_merci_printable_contract(&$variables) {
  $node = $variables['node'];
  setlocale(LC_MONETARY, 'en_US');
  $user = user_load($node->uid);
  $username = $user->name;
  $email = $user->mail;
  if (module_exists('civicrm')) {
    civicrm_initialize(TRUE);
    global $civicrm_root;

    //include_once($civicrm_root .'/api/UFGroup.php');

    //$userID = crm_uf_get_match_id($user->uid);
    require_once $civicrm_root . '/CRM/Core/BAO/UFMatch.php';
    $userID = CRM_Core_BAO_UFMatch::getContactId($user->uid);
    $civicrm = system_get_info('module', 'civicrm');
    if ($civicrm['version'] >= '4.4') {
      try {
        $contacts = civicrm_api3('contact', 'get', array(
          'contact_id' => $userID,
        ));
      } catch (CiviCRM_API3_Exception $e) {
        $error = $e
          ->getMessage();
      }
      $ob = $contacts['values'];
    }
    else {
      $cg = array(
        'contact_id' => $userID,
      );
      include_once $civicrm_root . '/api/v2/Contact.php';
      $ob = civicrm_contact_get($cg);
    }
    $username = $ob[$userID]['display_name'];
    $phone = $ob[$userID]['phone'];
  }
  $items = $node->merci_reservation_items;
  $langcode = $node->language;

  // Convert to site timezone.
  $start_date = merci_create_local_date_object($node->field_merci_date[LANGUAGE_NONE][0]['value']);
  $end_date = merci_create_local_date_object($node->field_merci_date[LANGUAGE_NONE][0]['end_value']);
  $hours = round((intval(date_format($end_date, "U")) - intval(date_format($start_date, "U"))) / 3600, 2);
  $variables['start_date'] = format_date($start_date
    ->format('U'));
  $variables['end_date'] = format_date($end_date
    ->format('U'));
  $variables['hours'] = $hours;
  $variables['username'] = $username;
  $variables['email'] = $email;
  if (isset($phone)) {
    $variables['phone'] = $phone;
  }
  $variables['items'] = $items;
}