1. <?php
  2. /**
  3. * @copyright Copyright (C) 2005 - 2011 CiviCRM LLC All rights reserved.
  4. * @license GNU Affero General Public License version 2 or later
  5. */
  6. // No direct access
  7. defined('_JEXEC') or die;
  8. jimport('joomla.plugin.plugin');
  9. /**
  10. * CiviCRM User Management Plugin
  11. *
  12. * @package Joomla
  13. * @subpackage JFramework
  14. * @since 1.6
  15. */
  16. class plgUserCivicrm extends JPlugin {
  17. /* resetNavigation after user is saved
  18. * Method is called after user data is stored in the database
  19. *
  20. * @param array $user Holds the new user data.
  21. * @param boolean $isnew True if a new user is stored.
  22. * @param boolean $success True if user was succesfully stored in the database.
  23. * @param string $msg Message.
  24. *
  25. * @return void
  26. * @since 1.6
  27. * @throws Exception on error.
  28. */
  29. function onUserAfterSave($user, $isnew, $success, $msg) {
  30. $app = JFactory::getApplication();
  31. self::civicrmResetNavigation();
  32. }
  33. /* resetNavigation after group is saved (parent/child may impact acl)
  34. * Method is called after group is stored in the database
  35. *
  36. * @var string The event to trigger after saving the data.
  37. *
  38. * @return void
  39. * @since 1.6
  40. * @throws Exception on error.
  41. */
  42. function onUserAfterSaveGroup($var) {
  43. $app = JFactory::getApplication();
  44. self::civicrmResetNavigation();
  45. }
  46. function onUserAuthorisation($var) {
  47. echo 'auth';exit();
  48. }
  49. /* delete uf_match record after user is deleted
  50. * Method is called after user is deleted from the database
  51. *
  52. * @param array $user Holds the user data.
  53. * @param boolean $success True if user was successfully removed from the database.
  54. * @param string $msg Message.
  55. *
  56. * @return void
  57. * @since 1.6
  58. * @throws Exception on error.
  59. */
  60. function onUserAfterDelete($user, $succes, $msg) {
  61. $app = JFactory::getApplication();
  62. // Instantiate CiviCRM
  63. define('CIVICRM_SETTINGS_PATH', JPATH_ROOT . '/' . 'administrator/components/com_civicrm/civicrm.settings.php');
  64. require_once CIVICRM_SETTINGS_PATH;
  65. require_once 'CRM/Core/ClassLoader.php';
  66. CRM_Core_ClassLoader::singleton()->register();
  67. require_once 'CRM/Core/Config.php';
  68. $civiConfig = CRM_Core_Config::singleton();
  69. // Reset Navigation
  70. require_once 'CRM/Core/BAO/UFMatch.php';
  71. CRM_Core_BAO_UFMatch::deleteUser($user['id']);
  72. }
  73. /* trigger navigation reset when the user logs in
  74. *
  75. * @user Joomla user object
  76. * @options array of options to pass
  77. *
  78. * @return void
  79. * @since 1.6
  80. */
  81. public function onUserLogin($user, $options = array()) {
  82. $app = JFactory::getApplication();
  83. if ( $app->isAdmin() ) {
  84. $jUser =& JFactory::getUser();
  85. $jId = $jUser->get('id');
  86. self::civicrmResetNavigation( $jId );
  87. }
  88. }
  89. // Reset CiviCRM user/contact navigation cache
  90. public function civicrmResetNavigation( $jId = null ) {
  91. // Instantiate CiviCRM
  92. define('CIVICRM_SETTINGS_PATH', JPATH_ROOT . '/' . 'administrator/components/com_civicrm/civicrm.settings.php');
  93. require_once CIVICRM_SETTINGS_PATH;
  94. require_once 'CRM/Core/ClassLoader.php';
  95. CRM_Core_ClassLoader::singleton()->register();
  96. require_once 'CRM/Core/Config.php';
  97. $config = &CRM_Core_Config::singleton();
  98. $cId = null;
  99. //retrieve civicrm contact ID if joomla user ID is provided
  100. if ( $jId ) {
  101. $params = array(
  102. 'version' => 3,
  103. 'uf_id' => $jId,
  104. 'return' => 'contact_id',
  105. );
  106. $cId = civicrm_api('uf_match', 'getvalue', $params);
  107. }
  108. // Reset Navigation
  109. require_once 'CRM/Core/BAO/Navigation.php';
  110. CRM_Core_BAO_Navigation::resetNavigation($cId);
  111. }
  112. }