File Source for business_node.module

business_node

# Source for file business_node.module Documentation is available at business_node.module

    <?php
    // $Id$

    /**
     * @file
     *  TODO: Enter file description here.
     */

    /**
     * Implementation of hook_block().
     */
    function business_node_block($op = 'list', $delta = 0, $edit = array()) {
      if ($op == 'list') {
        $blocks[0]['info'] = t('TODO: Fill in block description');
        // OPTIONAL: Add additional block descriptions here, if required.
        return $blocks;
      }
      else if ($op == 'configure') {
        // OPTIONAL: Enter form elements to add to block configuration screen, if required.
      }
      else if ($op == 'save') {
        // OPTIONAL: Add code to trigger when block configuration is saved, if required.
      }
      else if ($op == 'view') {
        switch ($delta) {
          case 0:
            $block['subject'] = t('TODO: Enter block title');
            $block['content'] = t('TODO: Enter block content');
            break;
          // OPTIONAL: Enter additional cases for each additional block, if defined.
        }
        return $block;
      }
    }

    /**
     * Implementation of hook_help().
     */
    function business_node_help($section) {
      switch ($section) {
        case 'admin/help#business_node':
          return t('Business Node');
        case 'admin/modules#description':
          return t('Business Node');
        case 'node/add#business_node':
          return t('TODO: enter description of node.');
        // OPTIONAL: Add additional cases for other paths that should display help text.
      }
    }

    /**
     * Implementation of hook_menu().
     */
    function business_node_menu($may_cache) {
      $items = array();

      if ($may_cache) {
        $items[] = array(
          'path' => 'node/add/business_node',
          'title' => t('Business Node'),
          'access' => user_access('create Business Node'),
          // OPTIONAL: Fill in other properties
        );
        // OPTIONAL: Fill in additional static menu items
      }
      // OPTIONAL: Put in else statement for dynamic menu items that can't be cached.

      return $items;
    }

    /**
     * Implementation of hook_nodeapi().
     */
    function business_node_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
      switch ($op) {
        case 'delete revision':
          // TODO: Enter revision deletion query here, for example:
          // db_query('DELETE FROM {node_example} WHERE vid = %d', $node->vid);
          break;
      }
    }

    /**
     * Implementation of hook_perm().
     */
    function business_node_perm() {
      return array('create Business Node', 'edit own Business Node');
    }

    /**
     * Implementation of hook_taxonomy().
     */
    function business_node_taxonomy($op, $type, $object) {

    }

    /**
     * Implementation of hook_access().
     */
    function business_node_access($op, $node) {
      global $user;

      if ($op == 'create') {
        return user_access('create Business Node');
      }

      if ($op == 'update' || $op == 'delete') {
        if (user_access('edit own Business Node') && ($user->uid == $node->uid)) {
          return TRUE;
        }
      }
    }

    /**
     * Implementation of hook_delete().
     */
    function business_node_delete(&$node) {
      // TODO: Enter database deletion query here, for example:
      // db_query('DELETE FROM {node_example} WHERE nid = %d', $node->nid);
    }

    /**
     * Implementation of hook_form().
     */
    function business_node_form(&$node, &$param) {
      $form['title'] = array(
        '#type' => 'textfield',
        '#title' => t('Name'),
        '#required' => TRUE,
        '#default_value' => $node->title,
        '#weight' => -5
      );
      $form['body'] = array(
        '#type' => 'textarea',
        '#title' => t('Description'),
        '#default_value' => $node->body,
        '#rows' => '10',
        '#required' => FALSE
      );
    //  $form['body_filter']['filter'] = filter_form($node->format);

          $form['keywords'] = array(
              '#type'    => 'textfield',
            '#title' => t('Keywords'),
            '#default_value' => $node->keywords,
            '#required' => FALSE,
            '#weight' => 1);
        $form['chamber_member'] = array(
              '#type'    => 'checkbox',
            '#title' => t('Chamber of Commerce Member'),
            '#default_value' => $node->chamber_member,
            '#required' => FALSE,
            '#weight' => 6);
          $form['url'] = array(
              '#type'    => 'textfield',
            '#title' => t('Website URL'),
            '#default_value' => $node->url,
            '#required' => FALSE,
            '#weight' => 3);
          $form['email'] = array(
              '#type'    => 'textfield',
            '#title' => t('Email Address'),
            '#default_value' => $node->email,
            '#required' => FALSE,
            '#weight' => 4);
          $form['contact'] = array(
              '#type'    => 'textfield',
            '#title' => t('Contact Person'),
            '#default_value' => $node->contact,
            '#required' => FALSE,
            '#weight' => 5);
        $form['address1'] = array(
            '#type' => 'fieldset',
            '#title' => t('Primary Address'),
            '#weight' => 10,
            '#collapsible' => TRUE,
            '#collapsed' => TRUE );
        $form['address1']['address1_line1'] = array(
            '#type' => 'textfield',
            '#title' => t('Address'),
            '#default_value' => $node->address1_line1,
            '#required' => FALSE,
            '#size' => 50,
            '#maxlength' => 50,
            '#weight' => -1);
        $form['address1']['address1_line2'] = array(
            '#type' => 'textfield',
            '#title' => '',
            '#default_value' => $node->address1_line2,
            '#required' => FALSE,
            '#size' => 50,
            '#maxlength' => 50,
            '#weight' => 0);
        $form['address1']['csz']['address1_city'] = array(
            '#type' => 'textfield',
            '#title' => t('City'),
            '#default_value' => $node->address1_city,
            '#size' => 50,
            '#maxlength' => 50,
            '#required' => FALSE);
        $form['address1']['csz']['address1_state'] = array(
            '#type' => 'textfield',
            '#title' => t('State'),
            '#default_value' => $node->address1_state,
            '#size' => 5,
            '#maxlength' => 2,
            '#required' => FALSE);
        $form['address1']['csz']['address1_zip'] = array(
            '#type' => 'textfield',
            '#title' => t('Zip Code'),
            '#default_value' => $node->address1_zip,
            '#size' => 10,
            '#maxlength' => 10,
            '#required' => FALSE);
        $form['address1']['map']['address1_showmap'] = array(
            '#type' => 'checkbox',
            '#title' => t('Show Map?'),
            '#default_value' => $node->address1_showmap,
            '#required' => FALSE);
        $form['address1']['map']['address1_latitude'] = array(
            '#type' => 'textfield',
            '#title' => t('Latitude'),
            '#default_value' => $node->address1_latitude,
            '#size' => 10,
            '#maxlength' => 10,
            '#required' => FALSE);
        $form['address1']['map']['address1_longitude'] = array(
            '#type' => 'textfield',
            '#title' => t('Longitude'),
            '#default_value' => $node->address1_longitude,
            '#size' => 10,
            '#maxlength' => 10,
            '#required' => FALSE);
        $form['address2'] = array(
            '#type' => 'fieldset',
            '#title' => t('Secondary Address'),
            '#weight' => 10,
            '#collapsible' => TRUE,
            '#collapsed' => TRUE );
        $form['address2']['address2_line1'] = array(
            '#type' => 'textfield',
            '#title' => t('Address'),
            '#default_value' => $node->address2_line1,
            '#required' => FALSE,
            '#size' => 50,
            '#maxlength' => 50,
            '#weight' => -1);
        $form['address2']['address2_line2'] = array(
            '#type' => 'textfield',
            '#title' => '',
            '#default_value' => $node->address2_line2,
            '#required' => FALSE,
            '#size' => 50,
            '#maxlength' => 50,
            '#weight' => 0);
        $form['address2']['csz']['address2_city'] = array(
            '#type' => 'textfield',
            '#title' => t('City'),
            '#default_value' => $node->address2_city,
            '#size' => 50,
            '#maxlength' => 50,
            '#required' => FALSE);
        $form['address2']['csz']['address2_state'] = array(
            '#type' => 'textfield',
            '#title' => t('State'),
            '#default_value' => $node->address2_state,
            '#size' => 5,
            '#maxlength' => 2,
            '#required' => FALSE);
        $form['address2']['csz']['address2_zip'] = array(
            '#type' => 'textfield',
            '#title' => t('Zip Code'),
            '#default_value' => $node->address2_zip,
            '#size' => 10,
            '#maxlength' => 10,
            '#required' => FALSE);
        $form['address2']['map']['address2_showmap'] = array(
            '#type' => 'checkbox',
            '#title' => t('Show Map?'),
            '#default_value' => $node->address2_showmap,
            '#required' => FALSE);
        $form['address2']['map']['address2_latitude'] = array(
            '#type' => 'textfield',
            '#title' => t('Latitude'),
            '#default_value' => $node->address2_latitude,
            '#size' => 10,
            '#maxlength' => 10,
            '#required' => FALSE);
        $form['address2']['map']['address2_longitude'] = array(
            '#type' => 'textfield',
            '#title' => t('Longitude'),
            '#default_value' => $node->address2_longitude,
            '#size' => 10,
            '#maxlength' => 10,
            '#required' => FALSE);

      // TODO: Enter additional form elements

      return $form;
    }

    /**
     * Implementation of hook_insert().
     */
    function business_node_insert($node) {
        // TODO: Enter database insertion query here, for example:
        // db_query("INSERT INTO {node_example} (vid, nid, color, quantity) VALUES (%d, %d, '%s', %d)", $node->vid, $node->nid, $node->color, $node->quantity);
          $fields = array('nid'                 => "%d",
                          'description'        => "'%s'",
                          'keywords'            => "'%s'",
                          'chamber_member'    => "%d",
                          'url'                => "'%s'",
                          'email'                => "'%s'",
                          'contact'            => "'%s'",
                          'address1_line1'    => "'%s'",
                          'address1_line2'    => "'%s'",
                          'address1_city'        => "'%s'",
                          'address1_state'    => "'%s'",
                          'address1_zip'      => "'%s'",
                          'address1_latitude'    => "%f",
                          'address1_longitude'=> "%f",
                          'address1_showmap'    => "%d",
                          'address2_line1'    => "'%s'",
                          'address2_line2'    => "'%s'",
                          'address2_city'        => "'%s'",
                          'address2_state'    => "'%s'",
                          'address2_zip'      => "'%s'",
                          'address2_latitude'    => "%f",
                          'address2_longitude'=> "%f",
                          'address2_showmap'    => "%d");

        $fields_str = join(',', array_keys($fields));
        $format_str = join(',', $fields);
        foreach($fields as $field=>$format)
        {
            $args[] = $node->$field;
        }
        db_query("INSERT INTO {business_node} ({$fields_str}) VALUES ({$format_str})", $args);

    }

    /**
     * Implementation of hook_load().
     */
    function business_node_load($node) {
      // TODO: Obtain and return additional fields added to the node type, for example:
      // $additions = db_fetch_object(db_query('SELECT color, quantity FROM {node_example} WHERE vid = %d', $node->vid));
      // return $additions;
      $additions = db_fetch_object(db_query('SELECT * FROM {business_node} WHERE nid = %d',$node->nid));
      return $additions;
    }

    /**
     * Implementation of hook_node_info().
     */
    function business_node_node_info() {
      return array('business_node' => array('name' => t('Business Node'), 'base' => 'business_node'));
    }

    /**
     * Implementation of hook_update().
     */
    function business_node_update($node) {
      if ($node->revision) {
        business_node_insert($node);
      } else {
          $fields = array('nid'                 => "%d",
                          'description'        => "'%s'",
                          'keywords'            => "'%s'",
                          'chamber_member'    => "%d",
                          'url'                => "'%s'",
                          'email'                => "'%s'",
                          'contact'            => "'%s'",
                          'address1_line1'    => "'%s'",
                          'address1_line2'    => "'%s'",
                          'address1_city'        => "'%s'",
                          'address1_state'    => "'%s'",
                          'address1_zip'      => "'%s'",
                          'address1_latitude'    => "%f",
                          'address1_longitude'=> "%f",
                          'address1_showmap'    => "%d",
                          'address2_line1'    => "'%s'",
                          'address2_line2'    => "'%s'",
                          'address2_city'        => "'%s'",
                          'address2_state'    => "'%s'",
                          'address2_zip'      => "'%s'",
                          'address2_latitude'    => "%f",
                          'address2_longitude'=> "%f",
                          'address2_showmap'    => "%d");
        // TODO: Enter database update query here, for example:
        // db_query("UPDATE {node_example} SET color = '%s', quantity = %d WHERE vid = %d", $node->color, $node->quantity, $node->vid);

        foreach($fields as $field=>$format)
        {
            $set_fields[] = "{$field} = {$format}";
            $args[] = $node->$field;
        }
        $fields_str = join(',', $set_fields);
        db_query("UPDATE {business_node} SET {$fields_str}", $args);
      }
    }

    /**
     * Implementation of hook_validate().
     */
    function business_node_validate(&$node) {
      // TODO: Enter form validation code here
    }

    /**
     * Implementation of hook_view().
     */
    function business_node_view(&$node, $teaser = FALSE, $page = FALSE) {
      // TODO: Insert additional code (call to theme functions, etc.) to execute when viewing a node, for example:
      // $node = node_prepare($node, $teaser);
      // $order_info = theme('node_example_order_info', $node);
      // $node->body .= $order_info;
      // $node->teaser .= $order_info;
    }
Documentation generated on Fri, 19 May 2006 15:51:17 -0700 by phpDocumentor 1.3.0RC3