You are here

function contribute_nodeapi in Contribute 6

File

./contribute.module, line 96
Lets users contribute to projects

Code

function contribute_nodeapi(&$node, $op, $teaser, $page) {
  global $user;
  switch ($op) {
    case 'load':
      $node->contribute_budget = contribute_get_node_budget($node->nid);
      break;
    case 'view':
      if ($user->uid == 0) {
        $node->content['contribute_form'] = array(
          '#value' => "Log in to contribute!",
        );
      }
      elseif ($page) {

        //Only proceed if the administrator has allowed contributions for this type of node
        $types_to_contribute = variable_get(contribute_node_types, array(
          'page',
        ));
        if (!in_array($node->type, $types_to_contribute, TRUE)) {
          break;
        }
        $budget = contribute_get_node_balance($node->nid);
        if ($budget > 0) {
          $node->content['contribute_form'] = array(
            '#value' => drupal_get_form('contribute_form', $node),
          );
        }
        else {
          $node->content['completed_already'] = array(
            '#value' => "This project is fully funded!. {$budget}",
          );
        }
      }
      break;
    case 'update':
      $budget = $node->budget;
      contribute_update_node_balance($node->nid, $budget);
      break;
    case 'insert':
      $budget = $node->field_budget[0]['value'];
      contribute_node_insert($node->nid, $budget);
      break;
  }
}