@import url( '/$path/../custom_templates/hrd.css' );\n" ); } function hrd_civicrm_dashboard( $contactID ) { hrd_initialize( ); $sql = array( ); $aclJoin = $aclWhere = null; if ( ! CRM_Core_Permission::check( 'access secure contacts' ) ) { $groupTable = 'civicrm_group_contact_hrd'; $aclJoin = "LEFT JOIN civicrm_group_contact $groupTable ON ( c.id = $groupTable.contact_id AND $groupTable.group_id = " . HRD_SECURE_GROUP_ID . " )"; $aclWhere = " ( $groupTable.status is null OR $groupTable.status != 'Added' ) "; } $nameJoin = "LEFT JOIN civicrm_contact ON (contact_id = civicrm_contact.id)"; $clause = " SELECT 'Contact' as type, c.id as id, c.id as contact_id, c.display_name as title, l.modified_date as date, display_name as name FROM civicrm_log l, civicrm_contact c $aclJoin WHERE l.entity_table = 'civicrm_contact' AND l.entity_id = c.id "; if ( $aclWhere ) { $clause .= " AND $aclWhere"; } $sql[] = $clause; $clause = " SELECT 'Event' as type, ce.id, null as contact_id, title as title, start_date as date, null as name FROM civicrm_event ce "; $sql[] = $clause; $clause = " SELECT 'Case' as type, cc.id, ccc.contact_id as contact_id, subject as title, start_date as date, display_name as name FROM civicrm_case cc, civicrm_case_contact ccc LEFT JOIN civicrm_contact c ON (ccc.contact_id = c.id) $aclJoin "; $clause .= " WHERE cc.id = ccc.case_id "; if ( $aclWhere ) { $clause .= " AND $aclWhere"; } $sql[] = $clause; if ( $aclJoin ) { $aclJoin = "LEFT JOIN civicrm_group_contact $groupTable ON ( ca.source_contact_id = $groupTable.contact_id AND $groupTable.group_id = " . HRD_SECURE_GROUP_ID . " )"; } $clause = " SELECT 'Activity' as type, ca.id, source_contact_id as contact_id, subject as title, activity_date_time as date, display_name as name FROM civicrm_activity ca $aclJoin LEFT JOIN civicrm_contact c ON (source_contact_id = c.id) "; if ( $aclWhere ) { $clause .= " WHERE $aclWhere"; } $sql[] = $clause; if ( $aclJoin ) { $aclJoin = "LEFT JOIN civicrm_group_contact $groupTable ON ( c.id = $groupTable.contact_id AND $groupTable.group_id = " . HRD_SECURE_GROUP_ID . " )"; } $clause = " SELECT 'Grant' as type, cg.id, cg.contact_id, cov.label as title, application_received_date as date, c.display_name as name FROM civicrm_grant cg, civicrm_option_value cov, civicrm_contact c $aclJoin "; $clause .= " WHERE cov.value = cg.grant_type_id AND cov.option_group_id = 22 AND cg.contact_id = c.id"; if ( $aclWhere ) { $clause .= " AND $aclWhere"; } $sql[] = $clause; foreach ( $sql as $id => $s ) { $sql[$id] = " ( $s ) "; } $sql = implode ( 'UNION', $sql ); $sql .= " ORDER BY date desc LIMIT " . HRD_MAX_ITEMS; $dao = CRM_Core_DAO::executeQuery( $sql ); $values = array( ); $html = " "; while ( $dao->fetch( ) ) { $title = hrd_make_link( $dao->type, $dao->title, $dao->id, $dao->contact_id, $dao->name ); $value['type' ] = $dao->type; $value['id' ] = $dao->id; $value['title'] = $title; $value['date' ] = $dao->date; $html .= " "; $values[] = $value; } $html .= "
Type Title Contact Date
{$value['type']} {$value['title']} "; if ( $dao->name && $dao->contact_id) { $url = CRM_Utils_System::url( 'civicrm/contact/view', "reset=1&cid={$dao->contact_id}" ); $html .= "($dao->name)"; } $html .= " {$value['date']}
"; return array( ts( 'Latest Transactions' ) => $html ); } function hrd_make_link( $type, $title, $id, $contactID, $name ) { switch ( $type ) { case 'Contact': $url = CRM_Utils_System::url( 'civicrm/contact/view', "reset=1&cid={$id}" ); break; case 'Event': $url = CRM_Utils_System::url( 'civicrm/event/info', "reset=1&id={$id}" ); break; case 'Activity': $url = CRM_Utils_System::url( 'civicrm/contact/view', "reset=1&cid={$contactID}&selectedChild=activity" ); break; case 'Case': $url = CRM_Utils_System::url( 'civicrm/contact/view', "reset=1&cid={$contactID}&selectedChild=case" ); break; case 'Grant': $url = CRM_Utils_System::url( 'civicrm/contact/view', "reset=1&cid={$contactID}&selectedChild=grant" ); break; default: $url = null; break; } $contactURL = CRM_Utils_System::url( 'civicrm/contact/view', "reset=1&cid={$contactID}" ); if ( $url ) { if ( ! $title ) { $title = ts( 'Link' ); } $title = "$title"; } return $title; } function hrd_civicrm_aclWhereClause( $type, &$tables, &$whereTables, &$contactID, &$where ) { hrd_initialize( ); if ( ! empty( $where ) ) { $where .= ' AND '; } else { $where = ''; } // if the contact has permission to access the secure contacts we // dont modify the clause if ( CRM_Core_Permission::check( 'access secure contacts' ) ) { $where .= ' ( 1 ) '; return; } // else modify the query so we can ensure that contactIDs belong to the secure group are not shown $groupTable = 'civicrm_group_contact_hrd'; $tables[$groupTable] = $whereTables[$groupTable] = "LEFT JOIN civicrm_group_contact $groupTable ON ( contact_a.id = $groupTable.contact_id AND $groupTable.group_id = " . HRD_SECURE_GROUP_ID . " )"; $where .= " ( $groupTable.status is null OR $groupTable.status != 'Added' ) "; } function hrd_civicrm_aclGroup( $type, $contactID, $tableName, &$allGroups, &$currentGroups ) { // only process saved search if ( $tableName != 'civicrm_saved_search' ) { return; } hrd_initialize( ); $currentGroups = $allGroups; if ( ! CRM_Core_Permission::check( 'access secure contacts' ) ) { unset( $currentGroups[HRD_SECURE_GROUP_ID] ); } $currentGroups = array_keys( $currentGroups ); } function hrd_perm( ) { return array( 'access secure contacts' ); }