<?php /** * @package Drupal Modules * @subpackage CiviCRM */ /** * */class nzg_CiviCRM { function init($pageTab = NULL) { if ($may_cache || substr($_GET['q'], 0, 20) == 'civicrm/contact/view') { /** * Add a tab button to the Contact View page via CiviCRM API as per * http://heydon.com.au/node/942 * * dlobo initially advised to hook it in directly via modifications * to Contact View page, so took that approach at first. This would * be better (because it is more modular) so will still see if this * is feasible. */ civicrm_initialize(TRUE); require_once 'CRM/Core/Menu.php'; // print_r(CRM_Core_Menu::$items); global $items ; $items[] = array( 'path' => 'civicrm/contact/view/interests', 'query' => 'reset=1&cid=%%cid%%', 'qs' => 'reset=1&cid=%%cid%%', // old? 'title' => t('Interests'), 'type' => CRM_Core_Menu::CALLBACK, 'crmType' => CRM_Core_Menu::LOCAL_TASK, 'callback' => 'nzg_civicrm_contact_view_page_interests', // 'interests', 'access' => 'access CiviCRM', 'weight' => 6, ); CRM_Core_Menu::add($items[count($items)-1]); } } /** * Render and return a tab page using CiviCRM and Smarty * * Based on code from http://heydon.com.au/node/942 */ function displayContactPageTab($pageTab = NULL) { // Firstly we initialise the CiviCRM API - this is done in nzInit() // civicrm_initialize(TRUE); require_once 'CRM/Core/Menu.php'; // was CRM/Utils/Menu.php require_once 'CRM/Core/BAO/CustomGroup.php'; // Because there are custom tabs attached to the contact page, You // need to add these to the menu as well. CRM_Core_Menu::addParam('cid', $_GET['cid']); // As a part of the menu item above there was a replacable field for // cid -> %%cid%% so that when the url is displayed it will be // replaced with the correct contact id. So this above will add the // information so the %%cid%% will be replaced in the menu. $contact = crm_get_contact(array('contact_id' => $_GET['cid'])); // We then set the title so that it will display the name of the // contact and the image which displays the contact. $image = CRM_Contact_BAO_Contact::getImage($contact->contact_type); CRM_Utils_System::setTitle( $image . ' ' . $contact->display_name ); // This block will add the custom tabs to the menu so that it looks // the same as the other parts of the contact pages. $startWeight = CRM_Core_Menu::getMaxWeight('civicrm/contact/view'); $startWeight++; CRM_Core_BAO_CustomGroup::AddMenuTabs($contact->contact_type, 'civicrm/contact/view/cd', $startWeight); // Lastly we create the CiviCRM Smarty object and set vars that // need to be past to the template. It is important to set the // tplFile which is a pointer to the template file for this // page. Then call the fetch('CRM/index.tpl') and the page will be // rendered for you, and it will look like it is a CiviCRM page that // was always meant to be there. $membership = array('one','two') ; // membership_load($contact->id); $template =& CRM_Core_Smarty::singleton(); $template->assign_by_ref('contact', $contact); $template->assign_by_ref('membership', $membership); $template->assign_by_ref('interest_areas', nzg_CiviCRM_Template::interestareas_form()) ; $template->assign('tplFile', 'CRM/Contact/Page/View/InterestAreas.tpl'); $output.= $template->fetch('CRM/index.tpl'); return $output; }}class nzg_CiviCRM_Template { function interestareas_form() { // retrieve taxonomy $taxonomy = taxonomy_form(9) ; // modify to our needs (eg add additional checkboxes) // return processed form return drupal_get_form('taxonomy_form_vocabulary', $taxonomy); }}// add the contact page tab to contact pagenzg_CiviCRM::init() ;/** * hook to add links to civicrm elements */function nzg_civicrm_civicrm_links( $op, $objectName, $objectId ) { if ( $op == 'tabs.contact.activity' && $objectName == 'Contact' ) { return array( array( 'id' => 'interests', 'url' => CRM_Utils_System::url( 'civicrm/contact/view/interests', "reset=1&snippet=1&cid={$objectId}" ), 'title' => 'Interests', 'weight' => 100, 'access' => 'access CiviCRM' ) ) ; }}/** * Implementation of Drupal _menu hook * * @return array */function nzg_civicrm_menu($may_cache) { if ( $may_cache ) { // things which should appear only when called in cacheable page } civicrm_initialize(TRUE); require_once('CRM/Core/Menu.php'); // add item which would make tab appear in correct location, except // for 403 error which appears instead - why is this? $items[] = array( 'path' => 'civicrm/contact/view/interests', 'qs' => 'reset=1&snippet=1&cid=%%cid%%', 'title' => t('Interests'), 'type' => MENU_CALLBACK, 'crmType' => CRM_Core_Menu::LOCAL_TASK, 'callback' => 'nzg_civicrm_contact_view_page_interests', 'access' => user_access('access CiviCRM'), ) ; // CRM_Core_Menu::add($items[count($items)-1]); // add item in wrong place, which doesn't get 403 and displays correctly $items[] = array( 'path' => 'contact/view/interests', 'qs' => 'reset=1&snippet=1&cid=%%cid%%', 'title' => t('Interests'), 'type' => MENU_CALLBACK, // 'crmType' => CRM_Core_Menu::LOCAL_TASK, 'callback' => 'nzg_civicrm_contact_view_page_interests', 'access' => user_access('access CiviCRM'), ) ; // CRM_Core_Menu::add($items[count($items)-1]); // pretty sure i shouldn't have to both use CRM_Core_Menu::add() // *and* return $items here return $items ;}function nzg_civicrm_contact_view_page_interests() { // if this is called via /drupal/contact/view/interests?reset=1&cid=1, then it works; // if called via /drupal/civicrm/contact/view/interests?reset=1&cid=1, then it 403s return nzg_CiviCRM::displayContactPageTab() ;}