| 1 |
<?php |
<?php |
| 2 |
// $Id: civimember_roles.module,v 1.3.2.4.2.3 2008/08/17 21:10:45 posco Exp $ |
// $Id: civimember_roles.module,v 1.3.2.4.2.4 2008/08/17 21:44:19 posco Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 16 |
'description' => t('Add/remove association rules and configure settings. Also perform manual synchronization.'), |
'description' => t('Add/remove association rules and configure settings. Also perform manual synchronization.'), |
| 17 |
'page callback' => 'civimember_roles_show_rules', |
'page callback' => 'civimember_roles_show_rules', |
| 18 |
'access callback' => 'user_access', |
'access callback' => 'user_access', |
| 19 |
'access arugments' => array('access settings'), |
'access arguments' => array('access settings'), |
| 20 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 21 |
); |
); |
| 22 |
$items['admin/settings/civimember_roles/show_rules'] = array( |
$items['admin/settings/civimember_roles/show_rules'] = array( |
| 23 |
'title' => t('List Association Rule(s)'), |
'title' => t('List Association Rule(s)'), |
| 24 |
'access callback' => 'user_access', |
'access callback' => 'user_access', |
| 25 |
'access arugments' => array('access settings'), |
'access arguments' => array('access settings'), |
| 26 |
'weight' => -5, |
'weight' => -5, |
| 27 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 28 |
); |
); |
| 31 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 32 |
'page arguments' => array('civimember_roles_add_rule_form'), |
'page arguments' => array('civimember_roles_add_rule_form'), |
| 33 |
'access callback' => 'user_access', |
'access callback' => 'user_access', |
| 34 |
'access arugments' => array('access settings'), |
'access arguments' => array('access settings'), |
| 35 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 36 |
); |
); |
| 37 |
$items['admin/settings/civimember_roles/configure'] = array( |
$items['admin/settings/civimember_roles/configure'] = array( |
| 38 |
'title' => t('Configure'), |
'title' => t('Configure'), |
| 39 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 40 |
'page arguments' => 'civimember_roles_configure', |
'page arguments' => array('civimember_roles_configure'), |
| 41 |
'access callback' => 'user_access', |
'access callback' => 'user_access', |
| 42 |
'access arugments' => array('access settings'), |
'access arguments' => array('access settings'), |
| 43 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 44 |
); |
); |
| 45 |
$items['admin/settings/civimember_roles/manual_sync'] = array( |
$items['admin/settings/civimember_roles/manual_sync'] = array( |
| 46 |
'title' => t('Manually Synchronize'), |
'title' => t('Manually Synchronize'), |
| 47 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 48 |
'page arguments' => 'civimember_roles_manual_sync', |
'page arguments' => array('civimember_roles_manual_sync'), |
| 49 |
'access callback' => 'user_access', |
'access callback' => 'user_access', |
| 50 |
'access arugments' => array('access settings'), |
'access arguments' => array('access settings'), |
| 51 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 52 |
); |
); |
| 53 |
|
|
| 382 |
* this function will only sync one user. |
* this function will only sync one user. |
| 383 |
*/ |
*/ |
| 384 |
function _civimember_roles_sync($ext_uid = NULL) { |
function _civimember_roles_sync($ext_uid = NULL) { |
| 385 |
|
civicrm_initialize(TRUE); |
| 386 |
|
|
| 387 |
//Bring in CRM_Core_BAO_UFMatch class so we can find Drupal UIDs |
//Bring in CRM_Core_BAO_UFMatch class so we can find Drupal UIDs |
| 388 |
global $civicrm_root; |
global $civicrm_root; |
| 404 |
LEFT JOIN civicrm_email ce ON cc.id = ce.contact_id |
LEFT JOIN civicrm_email ce ON cc.id = ce.contact_id |
| 405 |
WHERE contact_type = \'Individual\' |
WHERE contact_type = \'Individual\' |
| 406 |
AND ce.is_primary = 1 |
AND ce.is_primary = 1 |
| 407 |
AND membership_type_id = %1 |
AND membership_type_id = %1'; |
|
AND cc.domain_id = %2'; |
|
| 408 |
$params = array( |
$params = array( |
| 409 |
1 => array($result->type_id, 'Integer'), |
1 => array($result->type_id, 'Integer'), |
|
2 => array(CIVICRM_DOMAIN_ID, 'Integer') |
|
| 410 |
); |
); |
| 411 |
|
|
| 412 |
if (!empty($ext_uid)) { |
if (!empty($ext_uid)) { |
| 482 |
* This function returns an array of either membership types or status rules depending on the $type param. |
* This function returns an array of either membership types or status rules depending on the $type param. |
| 483 |
*/ |
*/ |
| 484 |
function _civimember_roles_get_data($type) { |
function _civimember_roles_get_data($type) { |
| 485 |
|
civicrm_initialize(TRUE); |
| 486 |
|
|
| 487 |
switch ($type) { |
switch ($type) { |
| 488 |
case 'status': |
case 'status': |
| 489 |
$sql = 'SELECT id, name FROM civicrm_membership_status WHERE domain_id = %1;'; |
$sql = 'SELECT id, name FROM civicrm_membership_status;'; |
| 490 |
break; |
break; |
| 491 |
|
|
| 492 |
case 'types': |
case 'types': |
| 493 |
$sql = 'SELECT id, name FROM civicrm_membership_type WHERE domain_id = %1;'; |
$sql = 'SELECT id, name FROM civicrm_membership_type;'; |
| 494 |
break; |
break; |
| 495 |
|
|
| 496 |
default: |
default: |
| 499 |
break; |
break; |
| 500 |
} |
} |
| 501 |
|
|
| 502 |
$params = array(1 => array(CIVICRM_DOMAIN_ID, 'Integer')); |
$dao =& CRM_Core_DAO::executeQuery($sql); |
|
$dao =& CRM_Core_DAO::executeQuery($sql, $params); |
|
| 503 |
|
|
| 504 |
$result = array(); |
$result = array(); |
| 505 |
while ($dao->fetch()) { |
while ($dao->fetch()) { |