| 1 |
<?php |
<?php |
|
|
|
| 2 |
/** |
/** |
| 3 |
* Project: CiviCRM: Constituent Relationship Management for NP's |
* Project: CiviCRM: Constituent Relationship Management for NP's |
| 4 |
* File: civicrm.module |
* File: civicrm.module |
| 23 |
* Drupal module file. |
* Drupal module file. |
| 24 |
* |
* |
| 25 |
* @package CRM |
* @package CRM |
| 26 |
* @author Donald A. Lobo <lobo@yahoo.com> |
* @copyright CiviCRM LLC (c) 2004-2009 |
|
* @copyright Donald A. Lobo 01/15/2005 |
|
| 27 |
* $Id$ |
* $Id$ |
| 28 |
* |
* |
| 29 |
*/ |
*/ |
| 30 |
|
|
|
include_once 'config.inc.php'; |
|
|
|
|
| 31 |
/** |
/** |
| 32 |
* Provides a link to the CSS stylesheet associated with this module. |
* Provides a link to the CSS stylesheet associated with this module. |
| 33 |
|
* and the javascript files needed by this module |
| 34 |
* |
* |
| 35 |
* @return a <style> tag that indicates what file browsers should import |
* @return a <style> tag that indicates what file browsers should import |
| 36 |
*/ |
*/ |
| 37 |
function civicrm_html_head() |
function civicrm_html_head() |
| 38 |
{ |
{ |
| 39 |
|
if ( ! civicrm_initialize( ) ) { |
| 40 |
|
return; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
require_once 'CRM/Core/Config.php'; |
require_once 'CRM/Core/Config.php'; |
| 44 |
$config =& CRM_Core_Config::singleton(); |
$config =& CRM_Core_Config::singleton(); |
| 45 |
return '<style type="text/css">@import url(' . $config->resourceBase . 'css/civicrm.css);</style>'; |
|
| 46 |
|
if ( isset( $config->customCSSURL ) && ! empty( $config->customCSSURL ) ) { |
| 47 |
|
$head = "<style type=\"text/css\">@import url({$config->customCSSURL});</style>\n"; |
| 48 |
|
} else { |
| 49 |
|
drupal_add_css(drupal_get_path('module', 'civicrm') . '/../css/civicrm.css'); |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
// include the below files ONLY if needed, since they are heavy weight ( i.e only for civicrm pages) |
| 53 |
|
$includeCommon = false; |
| 54 |
|
if ( arg(0) == 'civicrm' ) { |
| 55 |
|
$includeCommon = true; |
| 56 |
|
} else { |
| 57 |
|
$config->includeDojo = 0; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
if ( $includeCommon ) { |
| 61 |
|
$head .= "<style type=\"text/css\">@import url({$config->resourceBase}css/skins/aqua/theme.css);</style>\n"; |
| 62 |
|
$head .= "<script type=\"text/javascript\" src=\"{$config->userFrameworkResourceURL}packages/dojo/dojo/dojo.js\" djConfig=\"isDebug: false, parseOnLoad: true, usePlainJson: true\" ></script>"; |
| 63 |
|
$head .= "<script type=\"text/javascript\" src=\"{$config->userFrameworkResourceURL}packages/dojo/dojo/commonWidgets.js\"></script>"; |
| 64 |
|
$head .= "<style type=\"text/css\">@import url({$config->resourceBase}packages/dojo/dijit/themes/tundra/tundra.css);</style>"; |
| 65 |
|
$head .= "<script type=\"text/javascript\" src=\"{$config->resourceBase}js/calendar.js\"></script>"; |
| 66 |
|
$head .= "<script type=\"text/javascript\" src=\"{$config->resourceBase}js/lang/calendar-lang.php?{$config->lcMessages}\"></script>"; |
| 67 |
|
$head .= "<script type=\"text/javascript\" src=\"{$config->resourceBase}js/calendar-setup.js\"></script>"; |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
$template =& CRM_Core_Smarty::singleton( ); |
| 71 |
|
$head .= $template->fetch( 'CRM/common/jquery.tpl' ); |
| 72 |
|
|
| 73 |
|
return $head; |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
/** |
/** |
| 90 |
*/ |
*/ |
| 91 |
function civicrm_help($section) |
function civicrm_help($section) |
| 92 |
{ |
{ |
| 93 |
|
if ( ! civicrm_initialize( ) ) { |
| 94 |
|
return; |
| 95 |
|
} |
| 96 |
|
require_once 'CRM/Utils/System.php'; |
| 97 |
|
$docLinkAdmin = CRM_Utils_System::docURL2( "Administrator's Guide", true ); |
| 98 |
|
$docLinkAccess = CRM_Utils_System::docURL2( "Access Control", true ); |
| 99 |
switch ($section) { |
switch ($section) { |
|
case 'admin/modules#description': |
|
|
// This description is shown in the listing at admin/modules. |
|
|
return t('Constituent Relationship Management (CRM). Allows sites to manage contacts, relationships and groups, and track contact activities.'); |
|
|
|
|
| 100 |
case 'admin/help#civicrm': |
case 'admin/help#civicrm': |
| 101 |
|
$output = '<p>'. t('The CiviCRM module stores information on the universe of people associated with a community and on their interactions such as emails, donations, petitions, events, etc. It can act as a stand alone contact management system or it can be integrated with mass mailer, volunteer management, petition, and event finding. CiviCRM enables organizations to maintain all these activities in a single database, creating efficiencies and new opportunities for communities to better communicate and benefit from relationships with their community members.') .'</p>'; |
| 102 |
$output = '<p>'. t('The CiviCRM module stores information on the universe of people associated with a community and on their interactions such as emails, donations, petitions, events, etc. It can act as a stand alone contact management system or it can be integrated with mass mailer, volunteer management, petition, and event finding. CiviCRM enables organizations to maintain all these activities in a single database, creating efficiencies and new opportunities for communities to better communicate and benefit from relationships with their community members.') . '</p>'; |
$output .= '<p>'. t('The CiviCRM module allows you to create contacts, or import them from other sources. You can record relationships between contacts, such as indicating they live in the same household. There are two types of groups of contacts. You can create static groups which have a set list of contacts. You can also create dynamic (smart) groups based on characteristics that contacts have in common. For example, you could create a group of all contacts who live in California AND who have volunteered for your organization within the past year. The CiviCRM module also allows for tagging for less formal categorization of contacts or groups. You can easily extend CiviCRM to record community member information which is specific to your community or organization using custom fields. For example, you can create a set of fields to track volunteer skills and preferences. CiviCRM profile gives you a way to allow community members (\'users\') to update their own information, as well as share some of that information with others. Finally, you can configure custom activity types such as volunteering or attending events.') .'</p>'; |
| 103 |
|
$output .= '<p>' . t('You can:') . '</p>'; |
| 104 |
$output .= '<p>'. t('The CiviCRM module allows you to create contacts, or import them from other sources. You can record relationships between contacts, such as indicating they live in the same household. There are two types of groups of contacts. You can create static groups which have a set list of contacts. You can also create dynamic (smart) groups based on characteristics that contacts have in common. For example, you could create a group of all contacts who live in California AND who have volunteered for your organization within the past year. The CiviCRM module also allows for tagging for less formal categorization of contacts or groups. You can easily extend CiviCRM to record community member information which is specific to your community or organization using custom fields. For example, you can create a set of fields to track volunteer skills and preferences. CiviCRM profile gives you a way to allow community members (\'users\') to update their own information, as well as share some of that information with others. Finally, you can configure custom activity types such as volunteering or attending events.') .'</p>'; |
$output .= '<ul>'; |
| 105 |
|
$output .= '<li>' . t('read the <a href="!1">CiviCRM Administrator Guide</a>.', array('!1' => $docLinkAdmin)) . '</li>'; |
| 106 |
$output .= '<p>'. t('You can:') .'</p>'; |
$output .= '<li>' . t('enable CiviCRM blocks at <a href="!1">Administer » Site Building » Blocks</a>.', array('!1' => url('admin/build/block'))) . '</li>'; |
| 107 |
|
$output .= '<li>' . t('read about <a href="!1">CiviCRM access permissions</a> and set access permissions at <a href="!2">Administer CiviCRM » Access Control</a>.', array('!1' => $docLinkAccess, '!2' => url('civicrm/admin/access', array('query' => 'reset=1')))) . '</li>'; |
| 108 |
$output .= '<ul><li>'. t('enable CiviCRM blocks at %1.', array('%1' => l(t('administer') . ' >> ' . t('blocks'), 'admin/blocks'))) . '</li>'; |
$output .= '<li>' . t('find contacts by name, email address, group membership and or tagging at <a href="!1">Find Contacts</a>.', array('!1' => url('civicrm/contact/search/basic', array('query' => 'reset=1')))) . '</li>'; |
| 109 |
|
$output .= '<li>' . t('do complex searches based on tags, group membership, location, activities and custom fields at <a href="!1">Advanced Search</a>.', array('!1' => url('civicrm/contact/search/advanced', array('query' => 'reset=1')))) . '</li>'; |
| 110 |
$output .= '<li>' . t('set access permissions at %1.', array('%1' => l(t('administer') . ' >> ' . t('access control'), 'admin/access'))) . '</li>'; |
$output .= '<li>' . t('create or manage groups at <a href="!1">Manage Groups</a>.', array('!1' => url('civicrm/group', array('query' => 'reset=1')))) . '</li>'; |
| 111 |
|
$output .= '<li>' . t('import contacts from other sources at <a href="!1">Import Contacts</a>.', array('!1' => url('civicrm/import', array('query' => 'reset=1')))) . '</li>'; |
| 112 |
$output .= '<li>' . t('find contacts by name, email address, group membership and/or tagging at %1.', array('%1' => l(t('find contacts'), 'civicrm/contact/search/basic'))) . '</li>'; |
$output .= '<li>' . t('create or administer tags (e.g. organizer, foundation, environment...) at <a href="!1">CiviCRM » Administer » Tags</a>.', array('!1' => url('civicrm/admin/tag', array('query' => 'reset=1')))) . '</li>'; |
| 113 |
|
$output .= '<li>' . t('create or administer relationship types (e.g. household member, board member, spouse...) <a href="!1">CiviCRM » Administer » Relationship Types</a>.', array('!1' => url('civicrm/admin/reltype', array('query' => 'reset=1')))) . '</li>'; |
| 114 |
$output .= '<li>' . t('do complex searches based on tags, group membership, location, activities and custom fields at %1.', array('%1' => l(t('advanced search'), 'civicrm/contact/search/advanced'))) . '</li>'; |
$output .= '<li>' . t('create or administer location types (e.g. home, work, school...) <a href="!1">CiviCRM » Administer » Location Types</a>.', array('!1' => url('civicrm/admin/locationType', array('query' => 'reset=1')))) . '</li>'; |
| 115 |
|
$output .= '<li>' . t('create or administer activity types (e.g. house meeting, intake interview...) at <a href="!1">CiviCRM » Administer » Activity Types</a>.', array('!1' => url('civicrm/admin/options/activity_type', array('query' => 'group=activity_type&reset=1')))) . '</li>'; |
| 116 |
$output .= '<li>' . t('reuse a saved search at %1.', array('%1' => l(t('saved searches'), 'civicrm/contact/search/saved'))) . '</li>'; |
$output .= '<li>' . t('create or administer custom data fields (e.g. volunteer skills, emergency contact info...) <a href="!1">CiviCRM » Administer » Custom Data</a>.', array('!1' => url('civicrm/admin/custom/group', array('query' => 'reset=1')))) . '</li>'; |
| 117 |
|
$output .= '<li>' . t('create or administer CiviCRM profiles (i.e. what contact data is collected during user registration and included in My Account) at <a href="!1">CiviCRM » Administer » CiviCRM Profiles</a>.', array('!1' => url('civicrm/admin/uf/group', array('query' => 'reset=1')))) . '</li>'; |
| 118 |
$output .= '<li>' . t('create or manage groups at %1.', array('%1' => l(t('manage groups'), 'civicrm/group'))) . '</li>'; |
$output .= '</ul>'; |
| 119 |
|
$output .= '<p>'. t('For more information please refer to the <a href="!1">CiviCRM web-site</a> which includes project information, documentation and support resources and more.', array('!1' => 'http://civicrm.org')) .'</p>'; |
| 120 |
$output .= '<li>' . t('import contacts from other sources at %1.', array('%1' => l(t('import contacts'), 'civicrm/import'))) . '</li>'; |
return $output; |
| 121 |
|
case 'admin/modules#description': |
| 122 |
$output .= '<li>' . t('create or administer tags (e.g. organizer, foundation, environment...) at %1.', array('%1' => l(t('civicrm') . ' >> ' . t('admin') . ' >> ' . t('tags'), 'civicrm/admin/tag'))) . '</li>'; |
// This description is shown in the listing at admin/modules. |
| 123 |
|
return t('Constituent Relationship Management (CiviCRM !1). Allows sites to manage contacts, relationships and groups, and track contact activities, contributions, memberships and events. For more information please refer to the <a href="!2">CiviCRM web-site</a> which includes project information, documentation and support resources and more.', array('!1' => '2.1', '!2' => 'http://civicrm.org/')); |
|
$output .= '<li>' . t('create or administer relationship types (e.g. household member, board member, spouse...) at %1.', array('%1' => l(t('civicrm') . ' >> ' . t('admin') . ' >> ' . t('relationship types'), 'civicrm/admin/reltype'))) . '</li>'; |
|
|
|
|
|
$output .= '<li>' . t('create or administer location types (e.g. home, work, school...) at %1.', array('%1' => l(t('civicrm') . ' >> ' . t('admin') . ' >> ' . t('location types'), 'civicrm/admin/locationType'))) . '</li>'; |
|
|
|
|
|
$output .= '<li>' . t('create or administer activity types (e.g. house meeting, intake interview...) at %1.', array('%1' => l(t('civicrm') . ' >> ' . t('admin') . ' >> ' . t('activity types'), 'civicrm/admin/civicrm/admin/activityType'))) . '</li>'; |
|
|
|
|
|
$output .= '<li>' . t('create or administer custom data fields (e.g. volunteer skills, emergency contact info...) at %1.', array('%1-admin-custom-group' => l(t('civicrm') . ' >> ' . t('admin') . ' >> ' . t('custom data'), 'civicrm/admin/custom/group'))) . '</li>'; |
|
|
|
|
|
$output .= '<li>' . t('create or administer civicrm profile (i.e. what contact data is collected during user registration) at %1.', array('%1' => l(t('civicrm') . ' >> ' . t('admin') . ' >> ' . t('civicrm profile'), 'civicrm/admin/uf/group'))) . '</li></ul>'; |
|
|
|
|
|
$output .= '<p>'. t('For more information please read the <a href="%1">configuration and customization handbook CiviCRM page</a>.', array('%1' => 'http://www.drupal.org/handbook/modules/civicrm/')) .'</p>'; |
|
|
|
|
|
return $output; |
|
| 124 |
} |
} |
| 125 |
} |
} |
| 126 |
|
|
| 135 |
function civicrm_perm() |
function civicrm_perm() |
| 136 |
{ |
{ |
| 137 |
// make sure the system is initialized |
// make sure the system is initialized |
| 138 |
civicrm_initialize( ); |
if ( ! civicrm_initialize( ) ) { |
| 139 |
|
return; |
| 140 |
|
} |
| 141 |
|
|
| 142 |
// static permissions |
$config =& CRM_Core_Config::singleton(); |
|
$cPerm = array('add contacts', 'view all contacts', 'edit all contacts', |
|
|
'edit groups', 'administer CiviCRM', |
|
|
'access CiviCRM Profile Listings', |
|
|
'access CiviCRM' ); |
|
| 143 |
|
|
|
// dynamic permissions - access by group (title) |
|
|
require_once 'CRM/Core/PseudoConstant.php'; |
|
| 144 |
require_once 'CRM/Core/Permission.php'; |
require_once 'CRM/Core/Permission.php'; |
| 145 |
|
$permissions =& CRM_Core_Permission::basicPermissions( ); |
| 146 |
$groups =& CRM_Core_PseudoConstant::allGroup(); |
return array_keys( $permissions ); |
|
foreach ( $groups as $title ) { |
|
|
$cPerm[] = t( CRM_Core_Permission::VIEW_GROUPS . '%1', array('%1' => $title)); |
|
|
$cPerm[] = t( CRM_Core_Permission::EDIT_GROUPS . '%1', array('%1' => $title)); |
|
|
} |
|
|
|
|
|
return $cPerm; |
|
| 147 |
} |
} |
| 148 |
|
|
| 149 |
/** |
/** |
| 155 |
|
|
| 156 |
function civicrm_block($op='list', $delta='0') |
function civicrm_block($op='list', $delta='0') |
| 157 |
{ |
{ |
| 158 |
if ( ( arg(0) != 'civicrm' && arg(0) != 'admin' ) || ( ! user_access( 'access CiviCRM' ) ) ) { |
if ( $op == 'configure' ) { |
| 159 |
|
return; |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
if ( ! civicrm_initialize( ) ) { |
| 163 |
return; |
return; |
| 164 |
} |
} |
| 165 |
|
|
| 166 |
// The $op parameter determines what piece of information is being requested. |
// The $op parameter determines what piece of information is being requested. |
| 167 |
global $user; |
require_once 'CRM/Core/Block.php'; |
| 168 |
if ($user->uid) { |
|
| 169 |
require_once 'CRM/Core/Block.php'; |
// CRM_Core_Error::backtrace( "$op, $delta" ); |
| 170 |
|
|
| 171 |
$menu_arr = civicrm_menu(true); |
if ($op == 'list') { |
| 172 |
if ($op == 'list') { |
$block = CRM_Core_Block::getInfo(); |
| 173 |
$block = CRM_Core_Block::getInfo(); |
} else { |
| 174 |
} else { |
$block = CRM_Core_Block::getContent ($delta); |
|
$block = CRM_Core_Block::getContent ($delta); |
|
|
} |
|
|
return $block; |
|
| 175 |
} |
} |
| 176 |
|
return $block; |
| 177 |
} |
} |
| 178 |
|
|
| 179 |
/** |
/** |
| 192 |
* find a match, and execute civicrm_foo(). |
* find a match, and execute civicrm_foo(). |
| 193 |
* |
* |
| 194 |
*/ |
*/ |
| 195 |
function civicrm_menu($may_cache) |
function civicrm_menu( ) |
| 196 |
{ |
{ |
| 197 |
if ( $may_cache ) { |
if ( ! civicrm_initialize( ) ) { |
| 198 |
require_once 'CRM/Utils/Menu.php'; |
return; |
|
$items = CRM_Utils_Menu::items( ); |
|
|
return $items; |
|
|
} else { |
|
|
return array( ); |
|
| 199 |
} |
} |
| 200 |
|
|
| 201 |
|
return array( |
| 202 |
|
'civicrm' => array( |
| 203 |
|
'title' => 'CiviCRM', |
| 204 |
|
'access callback' => true, |
| 205 |
|
'page callback' => 'civicrm_invoke', |
| 206 |
|
'type' => 4, |
| 207 |
|
'weight' => 0, |
| 208 |
|
) |
| 209 |
|
); |
| 210 |
} |
} |
| 211 |
|
|
| 212 |
/** |
/** |
| 213 |
* Initialize CivicRM. Call this function from other modules too if |
* Initialize CiviCRM. Call this function from other modules too if |
| 214 |
* they use the CivicRM API. |
* they use the CiviCRM API. |
| 215 |
* |
* |
| 216 |
*/ |
*/ |
| 217 |
function civicrm_initialize() { |
function civicrm_initialize( ) |
| 218 |
static $initialized = false; |
{ |
| 219 |
|
// Check for php version and ensure its greater than 5. |
| 220 |
|
// do a fatal exit if |
| 221 |
|
if ( (int ) substr( PHP_VERSION, 0, 1 ) < 5 ) { |
| 222 |
|
echo "CiviCRM requires PHP Version 5.2 or greater. You are running PHP Version " . PHP_VERSION . "<p>"; |
| 223 |
|
exit( ); |
| 224 |
|
} |
| 225 |
|
|
| 226 |
if ( $initialized ) { |
static $initialized = false; |
| 227 |
return; |
static $failure = false; |
| 228 |
|
|
| 229 |
|
if ( $failure ) { |
| 230 |
|
return false; |
| 231 |
} |
} |
| 232 |
|
|
| 233 |
$initialized = true; |
if ( ! $initialized ) { |
| 234 |
|
if ( function_exists( 'conf_path' ) ) { |
| 235 |
|
$settingsFile = conf_path( ) . '/civicrm.settings.php'; |
| 236 |
|
} else { |
| 237 |
|
$settingsFile = conf_init( ) . '/civicrm.settings.php'; |
| 238 |
|
} |
| 239 |
|
$error = include_once( $settingsFile ); |
| 240 |
|
|
| 241 |
// this does pretty much all of the civicrm initialization |
// get ready for problems |
| 242 |
require_once 'CRM/Core/Config.php'; |
$docLinkInstall = "http://wiki.civicrm.org/confluence/display/CRMDOC/Drupal+Installation+Guide"; |
| 243 |
$config =& CRM_Core_Config::singleton(); |
$docLinkTrouble = "http://wiki.civicrm.org/confluence/display/CRMDOC/Installation+and+Configuration+Trouble-shooting"; |
| 244 |
|
$forumLink = "http://forum.civicrm.org/index.php/board,6.0.html"; |
| 245 |
|
|
| 246 |
|
$errorMsgAdd = t("Please review the <a href='!1'>Drupal Installation Guide</a> and the <a href='!2'>Trouble-shooting page</a> for assistance. If you still need help installing, you can often find solutions to your issue by searching for the error message in the <a href='!3'>installation support section of the community forum</a>.</strong></p>", |
| 247 |
|
array('!1' => $docLinkInstall, '!2' => $docLinkTrouble, '!3' => $forumLink ) ); |
| 248 |
|
|
| 249 |
|
|
| 250 |
|
if ( $error == false ) { |
| 251 |
|
$failure = true; |
| 252 |
|
drupal_set_message( "<strong><p class='error'>" . |
| 253 |
|
t("Oops! - The CiviCRM settings file (civicrm.settings.php) was not found in the expected location ") . |
| 254 |
|
"(" . $settingsFile . "). </p><p class='error'>" . |
| 255 |
|
$errorMsgAdd . '</p></strong>' ); |
| 256 |
|
return false; |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
// this does pretty much all of the civicrm initialization |
| 260 |
|
$error = include_once( 'CRM/Core/Config.php' ); |
| 261 |
|
if ( $error == false ) { |
| 262 |
|
$failure = true; |
| 263 |
|
drupal_set_message( "<strong><p class='error'>" . |
| 264 |
|
t("Oops! - The path for including CiviCRM code files is not set properly. Most likely there is an error in the <em>civicrm_root</em> setting in your CiviCRM settings file (!1).", |
| 265 |
|
array( '!1' => $settingsFile ) ) . |
| 266 |
|
"</p><p class='error'> » " . |
| 267 |
|
t("civicrm_root is currently set to: <em>!1</em>.", array( '!1' => $civicrm_root ) ) . |
| 268 |
|
"</p><p class='error'>" . $errorMsgAdd . "</p></strong>" ); |
| 269 |
|
return false; |
| 270 |
|
} |
| 271 |
|
|
| 272 |
// Add module-specific stylesheet to page header |
$initialized = true; |
|
drupal_set_html_head(civicrm_html_head()); |
|
| 273 |
|
|
| 274 |
if(arg(0) == 'civicrm') { |
// initialize the system by creating a config object |
| 275 |
// this is just for ease of use. once the code is solid, we no longer need this |
$config =& CRM_Core_Config::singleton(); |
| 276 |
// menu_rebuild(); |
|
| 277 |
|
// Add module-specific header elements |
| 278 |
|
drupal_set_html_head(civicrm_html_head()); |
| 279 |
} |
} |
| 280 |
|
|
| 281 |
|
return true; |
| 282 |
} |
} |
| 283 |
|
|
| 284 |
function civicrm_invoke() |
/** |
| 285 |
|
* Function to get the contact type |
| 286 |
|
* @param string $default contact type |
| 287 |
|
* |
| 288 |
|
* @return $ctype contact type |
| 289 |
|
*/ |
| 290 |
|
function civicrm_get_ctype( $default = null ) |
| 291 |
|
{ |
| 292 |
|
// here we are creating a new contact |
| 293 |
|
// get the contact type from the POST variables if any |
| 294 |
|
|
| 295 |
|
if ( isset( $_REQUEST['ctype'] ) ) { |
| 296 |
|
$ctype = $_REQUEST['ctype']; |
| 297 |
|
} else if ( isset( $_REQUEST['edit'] ) && |
| 298 |
|
isset( $_REQUEST['edit']['ctype'] ) ) { |
| 299 |
|
$ctype = $_REQUEST['edit']['ctype']; |
| 300 |
|
} else { |
| 301 |
|
$ctype = $default; |
| 302 |
|
} |
| 303 |
|
|
| 304 |
|
if ( $ctype != 'Individual' && |
| 305 |
|
$ctype != 'Organization' && |
| 306 |
|
$ctype != 'Household' ) { |
| 307 |
|
$ctype = $default; |
| 308 |
|
} |
| 309 |
|
return $ctype; |
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
/** |
| 313 |
|
* This is the main function that is called on any civicrm click |
| 314 |
|
* |
| 315 |
|
*/ |
| 316 |
|
function civicrm_invoke( ) |
| 317 |
{ |
{ |
| 318 |
// make sure the system is initialized |
// make sure the system is initialized |
| 319 |
civicrm_initialize( ); |
if ( ! civicrm_initialize( ) ) { |
| 320 |
|
return drupal_not_found( ); |
| 321 |
|
} |
| 322 |
|
|
| 323 |
|
civicrm_cache_disable( ); |
| 324 |
|
|
| 325 |
|
require_once 'CRM/Core/Error.php'; |
| 326 |
|
|
| 327 |
|
$args = explode( '/', $_GET['q'] ); |
| 328 |
|
|
| 329 |
// synchronize the drupal uid with the contacts db |
// synchronize the drupal uid with the contacts db |
| 330 |
global $user; |
global $user; |
|
require_once 'CRM/Core/BAO/UFMatch.php'; |
|
|
CRM_Core_BAO_UFMatch::synchronize( $user, false, 'Drupal' ); |
|
| 331 |
|
|
| 332 |
$args = explode( '/', $_GET['q'] ); |
/* FIXME: hack to bypass synchronize if running upgrade to avoid |
| 333 |
|
any serious non-recoverable error which might hinder the |
| 334 |
|
upgrade process. */ |
| 335 |
|
if ( !isset($args[1]) or $args[1] != 'upgrade' ) { |
| 336 |
|
require_once 'CRM/Core/BAO/UFMatch.php'; |
| 337 |
|
CRM_Core_BAO_UFMatch::synchronize( $user, false, 'Drupal', |
| 338 |
|
civicrm_get_ctype( 'Individual' ) ); |
| 339 |
|
} |
| 340 |
|
|
| 341 |
require_once 'CRM/Core/Invoke.php'; |
require_once 'CRM/Core/Invoke.php'; |
| 342 |
$ret = CRM_Core_Invoke::invoke( $args ); |
return CRM_Core_Invoke::invoke( $args ); |
|
|
|
|
return $ret; |
|
| 343 |
} |
} |
| 344 |
|
|
| 345 |
/** |
/** |
| 357 |
* |
* |
| 358 |
* @return mixed depends on the operation being performed |
* @return mixed depends on the operation being performed |
| 359 |
*/ |
*/ |
| 360 |
function civicrm_user( $type, &$edit, &$user, $category = NULL ) { |
function civicrm_user( $type, &$edit, &$user, $category = NULL ) |
| 361 |
if ( $type == 'load' ) { |
{ |
|
return; |
|
|
} |
|
|
|
|
|
// make sure the system is initialized |
|
|
civicrm_initialize( ); |
|
| 362 |
|
|
| 363 |
// CRM_Core_Error::debug( $type, $edit ); |
if ( $type == 'load' ) { |
| 364 |
|
return; |
| 365 |
|
} |
| 366 |
|
|
| 367 |
|
if ( ! civicrm_initialize( ) ) { |
| 368 |
|
return; |
| 369 |
|
} |
| 370 |
|
|
| 371 |
switch ( $type ) { |
switch ( $type ) { |
| 372 |
|
|
| 373 |
case 'login': |
case 'login': |
| 374 |
require_once 'CRM/Core/BAO/UFMatch.php'; |
require_once 'CRM/Core/BAO/UFMatch.php'; |
| 375 |
return CRM_Core_BAO_UFMatch::synchronize( $user, false, 'Drupal' ); |
return CRM_Core_BAO_UFMatch::synchronize( $user, false, 'Drupal', |
| 376 |
|
civicrm_get_ctype( 'Individual' ) ); |
| 377 |
|
|
| 378 |
case 'register': |
case 'register': |
| 379 |
return civicrm_register_data($edit, $user, $category, true); |
$config =& CRM_Core_Config::singleton( ); |
| 380 |
|
if ( $config->inCiviCRM ) { |
| 381 |
|
return; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
if ( empty( $_POST ) ) { |
| 385 |
|
return civicrm_register_data($edit, $user, $category, true, false ); |
| 386 |
|
} else { |
| 387 |
|
return civicrm_register_data( $edit, $user, $category, false, true ); |
| 388 |
|
} |
| 389 |
|
break; |
| 390 |
|
|
| 391 |
case 'insert': |
case 'insert': |
| 392 |
return civicrm_register_data($edit, $user, $category, false); |
$config =& CRM_Core_Config::singleton( ); |
| 393 |
|
if ( $config->inCiviCRM ) { |
| 394 |
|
return; |
| 395 |
|
} |
| 396 |
|
|
| 397 |
|
// did civicrm generate this page, or is it via a user hook? |
| 398 |
|
if ( civicrm_on_user_page( ) ) { |
| 399 |
|
return civicrm_register_data($edit, $user, $category, false); |
| 400 |
|
} else { |
| 401 |
|
require_once 'CRM/Core/BAO/UFMatch.php'; |
| 402 |
|
CRM_Core_BAO_UFMatch::synchronize( $user, false, 'Drupal', |
| 403 |
|
civicrm_get_ctype( 'Individual' ) ); |
| 404 |
|
} |
| 405 |
|
break; |
| 406 |
|
|
| 407 |
case 'view': |
case 'view': |
| 408 |
return civicrm_view_data($user); |
return civicrm_view_data($user); |
| 409 |
|
|
| 410 |
case 'update': |
case 'update': |
| 411 |
return civicrm_form_data($edit, $user, $category, false); |
// this always comes in via user hook, so udpate email only if it has changed |
| 412 |
|
if ( isset( $edit['mail'] ) && |
| 413 |
|
trim( $edit['mail'] ) != trim( $user->mail ) ) { |
| 414 |
|
require_once 'CRM/Core/BAO/UFMatch.php'; |
| 415 |
|
$contactID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
| 416 |
|
|
| 417 |
|
// cant find the contactID, so lets skip |
| 418 |
|
if ( ! $contactID ) { |
| 419 |
|
return; |
| 420 |
|
} |
| 421 |
|
CRM_Core_BAO_UFMatch::updateContactEmail( $contactID, |
| 422 |
|
trim( $edit['mail'] ) ); |
| 423 |
|
} |
| 424 |
|
break; |
| 425 |
|
|
| 426 |
case 'form': |
case 'form': |
| 427 |
return civicrm_form_data($edit, $user, $category, true); |
$inCategory = true; |
| 428 |
|
if ( $category ) { |
| 429 |
|
$inCategory = false; |
| 430 |
|
$categories = civicrm_categories( $account ); |
| 431 |
|
foreach ( $categories as $cat ) { |
| 432 |
|
if ( $category == $cat['name'] ) { |
| 433 |
|
$inCategory = true; |
| 434 |
|
break; |
| 435 |
|
} |
| 436 |
|
} |
| 437 |
|
} |
| 438 |
|
|
| 439 |
|
// only return a form to drupal my account page |
| 440 |
|
if ( $inCategory && |
| 441 |
|
arg(0) == 'user' && |
| 442 |
|
arg(2) == 'edit' && |
| 443 |
|
arg(3) ) { |
| 444 |
|
if ( empty( $_POST ) ) { |
| 445 |
|
return civicrm_form_data($edit, $user, $category, true, false ); |
| 446 |
|
} else { |
| 447 |
|
return civicrm_form_data($edit, $user, $category, true, true ); |
| 448 |
|
} |
| 449 |
|
} |
| 450 |
|
break; |
| 451 |
|
|
| 452 |
case 'validate': |
case 'validate': |
| 453 |
return civicrm_validate_data($edit, $user, $category); |
return civicrm_validate_data($edit, $user, $category); |
| 454 |
|
|
| 455 |
case 'categories': |
case 'categories': |
| 456 |
return civicrm_categories(); |
return civicrm_categories( $user ); |
| 457 |
|
|
| 458 |
|
case 'delete': |
| 459 |
|
require_once 'CRM/Core/BAO/UFMatch.php'; |
| 460 |
|
return CRM_Core_BAO_UFMatch::deleteUser( $user->uid ); |
| 461 |
} |
} |
| 462 |
|
|
| 463 |
} |
} |
| 464 |
|
|
| 465 |
function civicrm_categories( ) { |
/** |
| 466 |
|
* Determine if the user is on a CiviCRM generated page, i.e. the form has some civicrm unique token |
| 467 |
|
*/ |
| 468 |
|
function civicrm_on_user_page() { |
| 469 |
|
return isset( $_POST['_qf_default'] ); |
| 470 |
|
} |
| 471 |
|
|
| 472 |
|
|
| 473 |
|
function civicrm_categories( &$user ) |
| 474 |
|
{ |
| 475 |
|
if ( ! civicrm_initialize( ) ) { |
| 476 |
|
return; |
| 477 |
|
} |
| 478 |
|
|
| 479 |
require_once 'CRM/Core/BAO/UFGroup.php'; |
require_once 'CRM/Core/BAO/UFGroup.php'; |
| 480 |
$group =& new CRM_Core_DAO_UFGroup( ); |
require_once 'CRM/Core/BAO/UFField.php'; |
|
$group->is_active = 1; |
|
|
$group->orderBy( 'weight', 'title' ); |
|
|
$group->find( ); |
|
| 481 |
|
|
| 482 |
while ( $group->fetch( ) ) { |
$allUFGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Account'); |
| 483 |
$data[] = array( 'name' => $group->title, |
$ufGroups = array( ); |
| 484 |
'title' => $group->title, |
|
| 485 |
'weight' => $group->weight ); |
$weight = 100; |
| 486 |
|
foreach ($allUFGroups as $key => $value) { |
| 487 |
|
if ( $value['is_active'] ) { |
| 488 |
|
$ufGroups[] = array( 'name' => $value['name'], |
| 489 |
|
'title' => $value['name'], |
| 490 |
|
'weight' => $weight ); |
| 491 |
|
$weight += 10; |
| 492 |
|
} |
| 493 |
} |
} |
| 494 |
return $data; |
|
| 495 |
|
return $ufGroups; |
| 496 |
} |
} |
| 497 |
|
|
| 498 |
function civicrm_register_data($edit, &$user, $category, $reset) { |
function civicrm_register_data($edit, &$user, $category, $reset, $doNotProcess = false ) |
| 499 |
|
{ |
| 500 |
require_once 'CRM/Core/BAO/UFMatch.php'; |
require_once 'CRM/Core/BAO/UFMatch.php'; |
| 501 |
require_once 'CRM/Core/BAO/UFGroup.php'; |
require_once 'CRM/Core/BAO/UFGroup.php'; |
| 502 |
|
require_once 'CRM/Core/Action.php'; |
| 503 |
|
|
| 504 |
if ( $user->uid ) { |
// lets suppress key generation for all registration forms |
| 505 |
CRM_Core_BAO_UFMatch::synchronize( $user, true, 'Drupal' ); |
civicrm_key_disable( ); |
|
} |
|
|
|
|
|
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
|
| 506 |
|
|
| 507 |
if ( $userID ) { |
$ctype = civicrm_get_ctype( 'Individual' ); |
| 508 |
$html = CRM_Core_BAO_UFGroup::getEditHTML( $userID, '', CRM_Core_Action::UPDATE, true, $reset ); |
if ( $user->uid ) { |
| 509 |
|
// Happens on $type == 'insert' |
| 510 |
|
// $reset == false always |
| 511 |
|
// $doNotProcess == false always |
| 512 |
|
CRM_Core_BAO_UFMatch::synchronize( $user, true, 'Drupal', $ctype ); |
| 513 |
|
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
| 514 |
|
$html = CRM_Core_BAO_UFGroup::getEditHTML( $userID, '', |
| 515 |
|
2, |
| 516 |
|
true, |
| 517 |
|
$reset, null, |
| 518 |
|
$doNotProcess, $ctype ); |
| 519 |
} else { |
} else { |
| 520 |
$html = CRM_Core_BAO_UFGroup::getEditHTML( $userID, '', CRM_Core_Action::ADD, true, $reset ); |
// Happens on $type == 'register' |
| 521 |
|
$html = CRM_Core_BAO_UFGroup::getEditHTML( $userID, '', |
| 522 |
|
1, |
| 523 |
|
true, |
| 524 |
|
$reset, null, |
| 525 |
|
$doNotProcess, $ctype ); |
| 526 |
} |
} |
| 527 |
|
|
| 528 |
$output = array( ); |
$output = array( ); |
| 529 |
if ( $html ) { |
if ( $html ) { |
| 530 |
$output[] = array( 'title' => null, 'data' => $html, weight => 0 ); |
//$html = civicrm_add_jquery( $html ); |
| 531 |
|
$index = empty( $category ) ? 'civicrm-profile-register' : $category; |
| 532 |
|
$output[$index] = array( '#title' => $category, |
| 533 |
|
'#value' => $html, |
| 534 |
|
'#weight' => 1 ); |
| 535 |
} |
} |
| 536 |
|
|
| 537 |
return $output; |
return $output; |
| 538 |
} |
} |
| 539 |
|
|
| 540 |
function civicrm_form_data($edit, &$user, $category, $reset) { |
function civicrm_form_data($edit, &$user, $category, $reset, $doNotProcess = false) |
| 541 |
|
{ |
| 542 |
require_once 'CRM/Core/BAO/UFMatch.php'; |
require_once 'CRM/Core/BAO/UFMatch.php'; |
| 543 |
require_once 'CRM/Core/BAO/UFGroup.php'; |
require_once 'CRM/Core/BAO/UFGroup.php'; |
| 544 |
|
|
| 545 |
|
// lets suppress key generation for all CMS forms |
| 546 |
|
civicrm_key_disable( ); |
| 547 |
|
|
| 548 |
$output = array( ); |
$output = array( ); |
| 549 |
|
|
| 550 |
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
| 551 |
if ( ! $userID ) { |
if ( ! $userID ) { |
| 552 |
CRM_Core_BAO_UFMatch::synchronize( $user, false, 'Drupal' ); |
$ctype = civicrm_get_ctype( 'Individual' ); |
| 553 |
|
CRM_Core_BAO_UFMatch::synchronize( $user, false, 'Drupal', $ctype ); |
| 554 |
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
| 555 |
} |
} |
| 556 |
|
|
| 557 |
// at this point we better have a valid userID |
// at this point we better have a valid userID |
| 558 |
// else we hopefully aborted earlier |
if ( ! $userID ) { |
| 559 |
|
// we get into this scenario if we do not like the email address supplied by the user |
| 560 |
|
return; |
| 561 |
|
} |
| 562 |
|
|
| 563 |
// get all the data for this specific category |
$ctype = CRM_Core_DAO::getFieldValue( 'CRM_Contact_DAO_Contact', $userID, 'contact_type' ); |
| 564 |
$html = CRM_Core_BAO_UFGroup::getEditHTML( $userID, $category, null, false, $reset ); |
|
| 565 |
if ( $html ) { |
//to allow Edit any profile if user have permission |
| 566 |
$output[] = array( 'title' => $category, 'data' => $html, weight => 0 ); |
$profileID = CRM_Core_DAO::getFieldValue( "CRM_Core_DAO_UFGroup", $category, 'id', 'title' ); |
| 567 |
|
require_once 'CRM/Core/Permission.php'; |
| 568 |
|
$ufGroupIDs = CRM_Core_Permission::ufGroupClause( CRM_Core_Permission::EDIT, null, true ); |
| 569 |
|
|
| 570 |
|
if ( in_array($profileID, $ufGroupIDs) ) { |
| 571 |
|
// get all the data for this specific category |
| 572 |
|
$html = CRM_Core_BAO_UFGroup::getEditHTML( $userID, $category, null, false, $reset, null, $doNotProcess, $ctype ); |
| 573 |
|
} else { |
| 574 |
|
CRM_Core_Error::fatal( ts( 'The requested Profile (gid=%1) is disabled OR it is not configured to be used for \'Profile\' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.', |
| 575 |
|
array( 1 => $profileID ))); |
| 576 |
} |
} |
| 577 |
|
|
| 578 |
|
if ( $html ) { |
| 579 |
|
//$html = civicrm_add_jquery( $html ); |
| 580 |
|
$index = empty( $category ) ? 'civicrm-profile-my-account' : $category; |
| 581 |
|
$output[$index][] = array( '#title' => $category, |
| 582 |
|
'#value' => $html, |
| 583 |
|
'#weight' => 1 ); |
| 584 |
|
} |
| 585 |
|
|
| 586 |
return $output; |
return $output; |
| 587 |
} |
} |
| 588 |
|
|
| 589 |
function civicrm_view_data($user ) { |
function civicrm_view_data( &$user ) |
| 590 |
require_once 'CRM/Core/PseudoConstant.php'; |
{ |
|
$ufGroups =& CRM_Core_PseudoConstant::ufGroup( ); |
|
|
|
|
|
$data = array( ); |
|
|
|
|
| 591 |
require_once 'CRM/Core/BAO/UFMatch.php'; |
require_once 'CRM/Core/BAO/UFMatch.php'; |
|
|
|
| 592 |
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
| 593 |
if ( $userID ) { |
if ( $userID ) { |
| 594 |
|
// make sure user has permission to view the record |
| 595 |
|
require_once 'CRM/Contact/BAO/Contact.php'; |
| 596 |
|
require_once 'CRM/Contact/BAO/Contact/Permission.php'; |
| 597 |
|
$contactURL = null; |
| 598 |
|
if ( CRM_Core_Permission::check( 'access CiviCRM' ) && |
| 599 |
|
CRM_Contact_BAO_Contact_Permission::allow( $userID ) ) { |
| 600 |
|
$url = CRM_Utils_System::url( 'civicrm/contact/view', "reset=1&cid=$userID" ); |
| 601 |
|
$contactURL = '<a href="' .$url. '">» ' .t("View Contact Record") . '</a>'; |
| 602 |
|
} |
| 603 |
|
|
| 604 |
|
if ( CRM_Core_Permission::check( 'access Contact Dashboard' ) ) { |
| 605 |
|
$url = CRM_Utils_System::url( 'civicrm/user', "reset=1&id=$userID" ); |
| 606 |
|
if ( ! empty( $contactURL ) ) { |
| 607 |
|
$contactURL .= '<br/>'; |
| 608 |
|
} |
| 609 |
|
$contactURL .= '<a href="' .$url. '">» ' .t("View Contact Dashboard") . '</a>'; |
| 610 |
|
} |
| 611 |
|
|
| 612 |
require_once 'CRM/Profile/Page/Dynamic.php'; |
require_once 'CRM/Profile/Page/Dynamic.php'; |
| 613 |
|
require_once 'CRM/Core/BAO/UFGroup.php'; |
| 614 |
|
require_once 'CRM/Core/BAO/UFField.php'; |
| 615 |
|
|
| 616 |
|
$ctype = CRM_Core_DAO::getFieldValue( 'CRM_Contact_DAO_Contact', $userID, 'contact_type' ); |
| 617 |
|
|
| 618 |
|
$ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Account', 0, false); |
| 619 |
|
$weight = 100; |
| 620 |
foreach ( $ufGroups as $id => $title ) { |
foreach ( $ufGroups as $id => $title ) { |
| 621 |
$page =& new CRM_Profile_Page_Dynamic( $userID, $id ); |
|
| 622 |
$data[$title] = $page->run( ); |
$fieldType = CRM_Core_BAO_UFField::getProfileType( $id ); |
| 623 |
|
if ( ( $fieldType != 'Contact' ) && ( $fieldType != $ctype ) ) { |
| 624 |
|
continue; |
| 625 |
|
} |
| 626 |
|
$page =& new CRM_Profile_Page_Dynamic( $userID, $id, null, true ); |
| 627 |
|
$pageContent = $page->run( ); |
| 628 |
|
|
| 629 |
|
// CRM-3537: profile edit link |
| 630 |
|
$editURL = '» ' . l( "Edit '{$title['title']}'", |
| 631 |
|
"user/{$user->uid}/edit/{$title['title']}"); |
| 632 |
|
|
| 633 |
|
if ( $pageContent ) { |
| 634 |
|
$user->content[$title['title']] = |
| 635 |
|
array( '#title' => $title['title'], |
| 636 |
|
'#type' => 'user_profile_category', |
| 637 |
|
'#weight' => $weight ); |
| 638 |
|
$user->content[$title['title']][$title['title']] = |
| 639 |
|
array( '#type' => 'user_profile_item', |
| 640 |
|
'#value' => $pageContent . $editURL ); |
| 641 |
|
|
| 642 |
|
$weight += 10; |
| 643 |
|
} |
| 644 |
|
} |
| 645 |
|
|
| 646 |
|
if ( $contactURL ) { |
| 647 |
|
$user->content['urls'] = |
| 648 |
|
array( '#value' => $contactURL, |
| 649 |
|
'#weight' => $weight ); |
| 650 |
} |
} |
| 651 |
} |
} |
| 652 |
|
return; |
|
return $data; |
|
| 653 |
} |
} |
| 654 |
|
|
| 655 |
function civicrm_validate_data($edit, &$user, $title) { |
function civicrm_validate_data($edit, &$user, $title) |
| 656 |
require_once 'CRM/Utils/Array.php'; |
{ |
| 657 |
|
static $validated = false; |
| 658 |
|
|
| 659 |
// if this is an admin creator, dont validate |
if ( $validated ) { |
|
if ( ( $_GET['q'] == 'admin/user/create' ) || |
|
|
! CRM_Utils_Array::value( '_qf_default', $_POST ) ) { |
|
| 660 |
return; |
return; |
| 661 |
} |
} |
| 662 |
|
|
| 663 |
|
// lets suppress key generation for all validation also |
| 664 |
|
civicrm_key_disable( ); |
| 665 |
|
|
| 666 |
|
$validated = true; |
| 667 |
|
|
| 668 |
|
require_once 'CRM/Utils/Array.php'; |
| 669 |
|
|
| 670 |
require_once 'CRM/Core/BAO/UFMatch.php'; |
require_once 'CRM/Core/BAO/UFMatch.php'; |
| 671 |
require_once 'CRM/Core/BAO/UFGroup.php'; |
require_once 'CRM/Core/BAO/UFGroup.php'; |
| 672 |
|
|
| 673 |
$register = ( arg(1) == 'register' ) ? true : false; |
// check for either user/register or admin/user/user/create |
| 674 |
|
$register = ( arg(1) == 'register' || arg(3) == 'create' ) ? true : false; |
| 675 |
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
$userID = CRM_Core_BAO_UFMatch::getContactId( $user->uid ); |
| 676 |
if ( ! CRM_Core_BAO_UFGroup::isValid( $userID, $title, $register ) ) { |
$errors = CRM_Core_BAO_UFGroup::isValid( $userID, $title, $register ); |
| 677 |
|
if ( is_array( $errors ) ) { |
| 678 |
if ( $register ) { |
if ( $register ) { |
| 679 |
form_set_error( 'error', 'Please correct the errors indicated below...' ); |
foreach ( $errors as $name => $error ) { |
| 680 |
|
form_set_error( $name, $error ); |
| 681 |
|
} |
| 682 |
} else { |
} else { |
| 683 |
form_set_error( 'error', "Please complete and save required values in the tab $title" ); |
form_set_error( 'error', "Please complete and save required values in the tab $title" ); |
| 684 |
} |
} |
| 685 |
|
return false; |
| 686 |
} |
} |
| 687 |
return; |
return true; |
| 688 |
} |
} |
| 689 |
|
|
| 690 |
?> |
/** |
| 691 |
|
* Disable the drupal cache for all civicrm pages which should not be cached |
| 692 |
|
*/ |
| 693 |
|
function civicrm_cache_disable( ) { |
| 694 |
|
global $conf; |
| 695 |
|
$conf['cache'] = CACHE_DISABLED; |
| 696 |
|
} |
| 697 |
|
|
| 698 |
|
/** |
| 699 |
|
* Disable civicrm key for all forms that interact with the CMS |
| 700 |
|
* We do not control the CMS form generation and hence should suppress |
| 701 |
|
* qfKey |
| 702 |
|
*/ |
| 703 |
|
function civicrm_key_disable( ) { |
| 704 |
|
$config =& CRM_Core_Config::singleton( ); |
| 705 |
|
$config->keyDisable = true; |
| 706 |
|
} |
| 707 |
|
|
| 708 |
|
function civicrm_enable( ) { |
| 709 |
|
menu_rebuild( ); |
| 710 |
|
|
| 711 |
|
menu_link_maintain( 'civicrm', 'delete', 'civicrm', 'CiviCRM' ); |
| 712 |
|
|
| 713 |
|
$options = array( |
| 714 |
|
'link_title' => 'CiviCRM', |
| 715 |
|
'link_path' => 'civicrm/dashboard', |
| 716 |
|
'module' => 'civicrm', |
| 717 |
|
'options' => array( 'alter' => true ) |
| 718 |
|
); |
| 719 |
|
menu_link_save( $options ); |
| 720 |
|
|
| 721 |
|
if ( ! civicrm_initialize( ) ) { |
| 722 |
|
return; |
| 723 |
|
} |
| 724 |
|
|
| 725 |
|
// also invoke civicrm menu rebuild |
| 726 |
|
require_once 'CRM/Core/Menu.php'; |
| 727 |
|
CRM_Core_Menu::store( ); |
| 728 |
|
|
| 729 |
|
//Update the 'blocks' DB table with the blocks |
| 730 |
|
_block_rehash(); |
| 731 |
|
} |
| 732 |
|
|
| 733 |
|
/** |
| 734 |
|
* An implementation of hook_translated_menu_item_alter(). This is a hack |
| 735 |
|
* to hide the CiviCRM menu from the drupal navigation block for folks |
| 736 |
|
* who dont have access CiviCRM permissions |
| 737 |
|
**/ |
| 738 |
|
function civicrm_translated_menu_link_alter(&$item) { |
| 739 |
|
if ( $item['router_path'] == 'civicrm' && |
| 740 |
|
$item['module'] == 'civicrm' && |
| 741 |
|
! user_access( 'access CiviCRM' ) ) { |
| 742 |
|
$item['access_callback'] = $item['access'] = false; |
| 743 |
|
} |
| 744 |
|
} |
| 745 |
|
|
| 746 |
|
function civicrm_admin_menu( ) { |
| 747 |
|
if ( ! civicrm_initialize( ) ) { |
| 748 |
|
return; |
| 749 |
|
} |
| 750 |
|
|
| 751 |
|
$weight = 10; |
| 752 |
|
$links = array(); |
| 753 |
|
$links[] = array( |
| 754 |
|
'title' => 'CiviCRM', |
| 755 |
|
'path' => 'civicrm', |
| 756 |
|
'weight' => $weight, |
| 757 |
|
'options' => array( 'query' => 'reset=1' ) ); |
| 758 |
|
|
| 759 |
|
require_once 'CRM/Core/Menu.php'; |
| 760 |
|
$nav = CRM_Core_Menu::getNavigation( true ); |
| 761 |
|
|
| 762 |
|
foreach ( $nav as $key => $value ) { |
| 763 |
|
$weight += 10; |
| 764 |
|
$link = array( |
| 765 |
|
'title' => $value['title'], |
| 766 |
|
'path' => $value['path'], |
| 767 |
|
'weight' => $weight, |
| 768 |
|
'options' => array( 'query' => 'reset=1' ) ); |
| 769 |
|
|
| 770 |
|
if ( empty( $value['parent'] ) ) { |
| 771 |
|
$link['parent_path'] = 'CiviCRM'; |
| 772 |
|
} else { |
| 773 |
|
$link['parent_path'] = $nav[$value['parent']]['title']; |
| 774 |
|
} |
| 775 |
|
$links[] = $link; |
| 776 |
|
} |
| 777 |
|
|
| 778 |
|
return $links; |
| 779 |
|
|
| 780 |
|
} |
| 781 |
|
|
| 782 |
|
/** |
| 783 |
|
* Implementation of hook_views_api(). |
| 784 |
|
*/ |
| 785 |
|
function civicrm_views_api() { |
| 786 |
|
return array( |
| 787 |
|
'api' => 2, |
| 788 |
|
'path' => drupal_get_path('module', 'civicrm') . '/modules/views', |
| 789 |
|
); |
| 790 |
|
} |
| 791 |
|
|
| 792 |
|
function civicrm_add_jquery( &$html ) { |
| 793 |
|
return $html . '<script type="text/javascript">jQuery.noConflict(true);</script>'; |
| 794 |
|
} |