You are here

function patron_nodeapi in Library 6

Same name and namespace in other branches
  1. 5.2 patron/patron.module \patron_nodeapi()

Implemenation of hook_nodeapi().

File

patron/patron.module, line 155

Code

function patron_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($node->type == 'patron') {
    switch ($op) {
      case 'view':
        $node->title = $node->name_first . ' ' . $node->name_last;
        if (user_access('view patron content')) {
          $node->content['email'] = array(
            '#value' => '<div class="field-patron-email">' . patron_email_link($node) . '</div>',
            '#weight' => 0,
          );
        }
        if ($node->disabled == PATRON_DISABLED) {
          $node->content['disabled'] = array(
            '#value' => '<div class="field-patron-disabled">Disabled</div>',
            '#weight' => 2,
          );
        }
        if (variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER && !empty($node->patron_uid) && user_access('access user profiles')) {
          $patron_user = user_load($node->patron_uid);
          if ($patron_user) {
            $node->content['patron_uid'] = array(
              '#value' => '<div class="field-patron-user"><label>Drupal User: </label>' . l($patron_user->name, 'user/' . $patron_user->uid) . '</div>',
              '#weight' => -3,
            );
          }
        }
        if (variable_get('patron_use_barcodes', PATRON_NO_BARCODES) == PATRON_BARCODES) {
          $node->content['barcode'] = array(
            '#value' => '<div class="field-patron-barcode"><label>Card Number: </label>' . $node->barcode . '</div>',
            '#weight' => -1,
          );
        }
        global $user;
        watchdog('library', '%user viewed patron %name', array(
          '%user' => $user->name,
          '%name' => $node->title,
        ));
        break;
      case 'presave':
        if (!empty($node->email) && variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER) {
          $patron_uid = db_result(db_query_range("SELECT uid from {users} where mail= '%s'", $node->email, 0, 1));
          if ($patron_uid) {
            $node->patron_uid = $patron_uid;
            $node->uid = $patron_uid;
          }
          else {
            $node->patron_uid = NULL;
          }
        }
        break;
    }
  }
}