Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
03a799a290 | ||
|
adc61f2d58 | ||
|
2bbbf9aa43 | ||
|
98a9042f94 | ||
|
2cf7197082 | ||
|
6166e0b41e | ||
|
03c517e3aa | ||
|
0ad2f42fa2 | ||
|
7cb8bff32c | ||
|
3422d6b46c | ||
|
b64cef5627 | ||
|
e1d93ac1cf | ||
|
13f10399e9 | ||
|
3802edc486 | ||
|
4c192235e7 | ||
|
de6827f80b | ||
|
776f666d94 | ||
|
35485af11d | ||
|
e72264f058 | ||
|
ec1e8314c7 | ||
|
4333b6ca8e | ||
|
32bfadcb66 | ||
|
1d79d93af5 | ||
|
797a94eccb | ||
|
39d7d3ff75 | ||
|
59a2ab2bf5 | ||
|
9488f1a0b3 | ||
|
99838677b7 | ||
|
27702f4d80 | ||
|
f07759184e | ||
|
d60bdb098b | ||
|
b17dd2d8b4 | ||
|
2d003153df | ||
|
f2247b7c29 | ||
|
bcbadc64fe | ||
|
8b88267991 | ||
|
ce057368e2 | ||
|
b9cca6e139 | ||
|
f123890b01 | ||
|
7103382fec | ||
|
5845e4d512 | ||
|
59b353ed8c | ||
|
fcf17df571 | ||
|
25ac625ebc | ||
|
4bd5c885f6 | ||
|
bce5c1e0fe |
5
.buildpath
Normal file
5
.buildpath
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<buildpath>
|
||||
<buildpathentry kind="src" path=""/>
|
||||
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
|
||||
</buildpath>
|
28
.project
Normal file
28
.project
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Fancy Tokens</name>
|
||||
<comment>This file and the .buildpath file make Eclipse happy</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.php.core.PHPNature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
29
README.md
29
README.md
@ -1,6 +1,6 @@
|
||||
Install this extension as you would any other CiviCRM extension. If you are using Drupal Webforms and your Drupal tables are in a different database than your CiviCRM tables then you will need to verify that the CiviCRM database user has permission to query tables in the Drupal database.
|
||||
|
||||
This extension provides additional mail merge tokens for CiviCRM for use in emails, mass emails, or PDF letters. All the token descriptions start with "Community News & Enagagement".
|
||||
This extension provides additional mail merge tokens for CiviCRM for use in emails, mass emails, or PDF letters. All the tokens are under one of the following token categories: "Events", "Contribution Pages", "Forms" or "Greetings"
|
||||
|
||||
Main features:
|
||||
|
||||
@ -10,6 +10,29 @@ Main features:
|
||||
|
||||
C) There is a token for each of the next X event registration pages ( i.e. future events that also have online registration enabled). The token includes the event ID which can be manually changed to any valid event ID. The hyperlink will include the checksum for the recipient.
|
||||
|
||||
D) There is one token for each active profile that does not use any fields that would prevent it from being used as a stand-alone profile form. For example, it does not create tokens for profiles that use participant or contribution fields. This token will produce a hyperlink that includes the checksum for the recipient. The clickable text will be the title of the profile.
|
||||
D) There is a token for each active Petition (Petitions are part of CiviCampaign) The hyperlink will include the checksum for the recipient.
|
||||
|
||||
E) If this extension is running under Drupal and the CiviCRM-WebForm integration module is installed, then one token will be created for each published WebForm. (This logic checks if Drupal is in use before attempting to call any Drupal APIs. So this extension is safe to use with WordPress, Joomla and Stand-Alone.
|
||||
E) There is one token for each active profile that does not use any fields that would prevent it from being used as a stand-alone profile form. For example, it does not create tokens for profiles that use participant or contribution fields. This token will produce a hyperlink that includes the checksum for the recipient. The clickable text will be the title of the profile.
|
||||
|
||||
F) If this extension is running under Drupal and the CiviCRM-WebForm integration module is installed, then one token will be created for each published WebForm. (This logic checks if Drupal is in use before attempting to call any Drupal APIs. So this extension is safe to use with WordPress, Joomla and Stand-Alone. (Note: The only version of Drupal this has been tested with is Drupal7.)
|
||||
|
||||
G) There are a set of tokens under the category "Greetings" that provide convenient tokens for addressing married couples, households, and also single people. For example, Sometimes you want to use the nickname if not empty, otherwise fallback to their first name. (The greetings for couples currently only work for the English language)
|
||||
Greeting tokens:
|
||||
|
||||
'greetings.joint_casual' - 'Casual: Mike and Judy Kline (Uses nickname if available) '
|
||||
|
||||
'greetings.solo_casual' - 'Casual: Mike Kline (Uses nickname if available, does not show spouse) '
|
||||
|
||||
'greetings.joint_casual_firstname_lastname' - 'Casual first name and last name: Michael and Judith Kline'
|
||||
|
||||
'greetings.joint_casual_nickname_only' - 'Casual nickname only: Mike and Judy (Uses nickname if available)'
|
||||
|
||||
'greetings.solo_casual_nickname_only' - 'Casual nickname only: Mike(Uses nickname if available, does not show spouse)'
|
||||
|
||||
'greetings.joint_casual_firstname_only' - 'Casual first name only: Michael and Judith'
|
||||
|
||||
'greetings.joint_formal' - 'Formal: Mr. and Mrs. Kline'
|
||||
|
||||
'greetings.joint_formal_firstname' - 'Formal with first name: Mr. and Mrs. Michael Kline'
|
||||
|
||||
If any of these greeting tokens are used for an organization, then the display name is used.
|
||||
|
339
fancytokens.php
339
fancytokens.php
@ -29,7 +29,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
$e_id = $dao->id;
|
||||
$e_title = $dao->title;
|
||||
$e_start_date = $dao->start_date;
|
||||
$label = 'Registration Page: '.$e_title.' on '.$e_start_date.' (id: '.$e_id.') :: Events';
|
||||
$label = 'Registration Page: '.$e_title.' '.$e_start_date.' (id: '.$e_id.') :: Events';
|
||||
$key = 'communitynews.event_registrationpage___'.$e_id ;
|
||||
|
||||
$tokens['communitynews'][$key] = $label;
|
||||
@ -58,6 +58,27 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
}
|
||||
}
|
||||
|
||||
// Create tokens for all active Petitions ( part of CiviCampaign)
|
||||
$params = array(
|
||||
'sequential' => 1,
|
||||
'is_active' => 1,
|
||||
'activity_type_id.name' => 'Petition',
|
||||
);
|
||||
$result = civicrm_api3('Survey', 'get', $params);
|
||||
if( $result['is_error'] <> 0 ){
|
||||
print "<br><br>Error calling get API for Survey-Petition";
|
||||
print_r($result);
|
||||
}else{
|
||||
$petitions = $result['values'] ;
|
||||
foreach($petitions as $cur){
|
||||
|
||||
$key = 'communitynews.signpetition___'.$cur['id'] ;
|
||||
$label = $cur['title'].' (id: '.$cur['id'].') :: Petitions';
|
||||
|
||||
$tokens['communitynews'][$key] = $label;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get all active profiles and create tokens for the ones that can be stand-alone.
|
||||
$params = array(
|
||||
@ -78,17 +99,19 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
$p_type = "";
|
||||
if( isset( $cur['group_type'])){
|
||||
$p_type = $cur['group_type'];
|
||||
// Some group_types are arrays, if the profile is used on an event form
|
||||
$p_type = is_array($p_type) ? $p_type[0] : $p_type;
|
||||
|
||||
}
|
||||
$type_array = explode( "," , $p_type); // Contributions Activity
|
||||
if ( false == ( in_array("Participant", $type_array ) || in_array("Membership", $type_array ) || in_array("Household", $type_array ) || in_array("Contributions", $type_array ) || in_array("Activity", $type_array ) )) {
|
||||
$type_array = explode( "," , $p_type); // Contributions Activity
|
||||
if ( false == ( in_array("Participant", $type_array ) || in_array("Membership", $type_array ) || in_array("Household", $type_array ) || in_array("Contributions", $type_array ) || in_array("Activity", $type_array ) )) {
|
||||
|
||||
$key = 'communitynews.standaloneprofile___'.$cur['id'] ;
|
||||
$label = $cur['title'].' (id: '.$cur['id'].') :: Forms';
|
||||
$key = 'communitynews.standaloneprofile___'.$cur['id'] ;
|
||||
$label = $cur['title'].' (id: '.$cur['id'].') :: Forms';
|
||||
|
||||
$tokens['communitynews'][$key] = $label;
|
||||
$tokens['communitynews'][$key] = $label;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,32 +123,75 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
//print "<br><br>";
|
||||
//print_r($config);
|
||||
if ($config->userSystem->is_drupal){
|
||||
if( module_exists( "webform_civicrm") && module_exists( "webform_civicrm")){
|
||||
if (function_exists("module_exists") && module_exists("webform_civicrm")) {
|
||||
|
||||
$drupal_db = getUserFrameworkDatabaseName();
|
||||
$sql = "SELECT cforms.nid, node.title FROM $drupal_db.webform_civicrm_forms cforms
|
||||
JOIN $drupal_db.node ON cforms.nid = node.nid AND node.status = 1 ";
|
||||
//$drupal_db = getUserFrameworkDatabaseName();
|
||||
//$sql = "SELECT cforms.nid, node.title FROM $drupal_db.webform_civicrm_forms cforms
|
||||
// JOIN $drupal_db.node ON cforms.nid = node.nid AND node.status = 1 ";
|
||||
|
||||
$dsql = "SELECT cforms.nid, node.title FROM {webform_civicrm_forms} cforms
|
||||
JOIN {node} node ON cforms.nid = node.nid AND node.status = 1 ";
|
||||
|
||||
// LEFT JOIN url_alias ua ON cforms.nid = substr( ua.source) AND ua.source LIKE 'node/%'
|
||||
$dao =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray ) ;
|
||||
$dq_result = db_query( $dsql );
|
||||
|
||||
foreach ($dq_result as $record) {
|
||||
$nid = $record->nid;
|
||||
$title = $record->title;
|
||||
|
||||
while($dao->fetch()){
|
||||
$nid = $dao->nid;
|
||||
$title = $dao->title;
|
||||
//$url_alias = $dao->alias;
|
||||
$key = 'communitynews.dwform___'.$nid ;
|
||||
$label = "$title (nid: $nid) :: Forms";
|
||||
|
||||
$tokens['communitynews'][$key] = $label;
|
||||
|
||||
|
||||
}
|
||||
$dao->free();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$tok_category_label = " :: Greetings";
|
||||
|
||||
$tokens['greetings'] = array(
|
||||
'greetings.joint_casual' => 'Casual: Mike and Judy Kline (Uses nickname if available) '.$tok_category_label,
|
||||
'greetings.solo_casual' => 'Casual: Mike Kline (Uses nickname if available, does not show spouse) '.$tok_category_label,
|
||||
'greetings.joint_casual_firstname_lastname' => 'Casual first name and last name: Michael and Judith Kline'.$tok_category_label,
|
||||
'greetings.joint_casual_nickname_only' => 'Casual nickname only: Mike and Judy (Uses nickname if available)'.$tok_category_label,
|
||||
'greetings.solo_casual_nickname_only' => 'Casual nickname only: Mike(Uses nickname if available, does not show spouse)'.$tok_category_label,
|
||||
'greetings.joint_casual_firstname_only' => 'Casual first name only: Michael and Judith'.$tok_category_label,
|
||||
'greetings.joint_formal' => 'Formal: Mr. and Mrs. Kline'.$tok_category_label,
|
||||
'greetings.joint_formal_firstname' => 'Formal with first name: Mr. and Mrs. Michael Kline'.$tok_category_label,
|
||||
|
||||
);
|
||||
|
||||
|
||||
$tok_category_label = " :: Dates";
|
||||
|
||||
$tokens['dates'] = array(
|
||||
'dates.today' => 'Today (m/d/yyyy)'.$tok_category_label,
|
||||
'dates.today___j_F_yyyy' => 'Today (d monthname yyyy)'.$tok_category_label,
|
||||
'dates.today___F_j_yyyy' => 'Today (monthname d, yyyy)'.$tok_category_label,
|
||||
'dates.birth_date___F_j' => 'Birth Date (monthname d)'.$tok_category_label,
|
||||
'dates.checksum_expiration' => 'Checksum Expiration Date '.$tok_category_label,
|
||||
);
|
||||
|
||||
$tok_category_label = " :: Communication";
|
||||
$tokens['communication'] = array(
|
||||
'communication.phone_all' => 'All Phone Numbers'.$tok_category_label,
|
||||
'communication.email_all' => 'All Email Addresses'.$tok_category_label,
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function getUserFrameworkDatabaseName(){
|
||||
// ['userFrameworkDSN'] => mysql://dev1_username:mypassword@localhost/dev1_main?new_link=true
|
||||
|
||||
@ -147,14 +213,166 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
function fancytokens_civicrm_tokenValues( &$values, &$contactIDs, $job = null, $tokens = array(), $context = null) {
|
||||
|
||||
|
||||
|
||||
if(!empty($tokens['dates'])){
|
||||
// deal with tokens for 'today', birth_date', and similar.
|
||||
|
||||
$today = date_create();
|
||||
|
||||
$checksum_expire_result = civicrm_api3('Setting', 'get', [ 'sequential' => 1, 'return' => ["checksum_timeout"], ]);
|
||||
$checksum_expire_date_tmp = "" ;
|
||||
|
||||
if ($checksum_expire_result['is_error'] == 0 && $checksum_expire_result['count'] == 1){
|
||||
$tmp_checksum_int = $checksum_expire_result['values'][0]['checksum_timeout'];
|
||||
$interval_str = $tmp_checksum_int." days" ;
|
||||
$exp_date = date_create();
|
||||
date_add($exp_date, date_interval_create_from_date_string($interval_str));
|
||||
$checksum_expire_date_tmp = date_format($exp_date, 'F j');
|
||||
}else{
|
||||
|
||||
# print_r( $checksum_expire_result );
|
||||
}
|
||||
|
||||
foreach ( $contactIDs as $cid ) {
|
||||
$values[$cid]['dates.today'] = date("n/j/Y");
|
||||
$values[$cid]['dates.today___j_F_yyyy'] = date("j F Y");
|
||||
$values[$cid]['dates.today___F_j_yyyy'] = date("F j, Y");
|
||||
$values[$cid]['dates.checksum_expiration'] = $checksum_expire_date_tmp ;
|
||||
|
||||
}
|
||||
|
||||
$birthday_token = 'dates.birth_date___F_j' ;
|
||||
|
||||
|
||||
while( $cur_token_raw = current( $tokens['dates'] )){
|
||||
|
||||
$tmp_key = key($tokens['dates']);
|
||||
$cur_token = '';
|
||||
if( is_numeric( $tmp_key)){
|
||||
$cur_token = $cur_token_raw;
|
||||
}else{
|
||||
// Its being used by CiviMail.
|
||||
$cur_token = $tmp_key;
|
||||
}
|
||||
|
||||
$token_to_fill = 'dates.'.$cur_token;
|
||||
|
||||
if($token_to_fill == $birthday_token ){
|
||||
|
||||
$sql_cids = implode( ",", $contactIDs);
|
||||
|
||||
if( strlen( $sql_cids) > 0 ){
|
||||
$sql = "select c.id as contact_id, date_format( c.birth_date, '%M %e') as birth_date
|
||||
FROM civicrm_contact c
|
||||
WHERE c.id IN ( ".$sql_cids." )
|
||||
ORDER BY c.id" ;
|
||||
$dao =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray ) ;
|
||||
|
||||
|
||||
|
||||
while($dao->fetch()){
|
||||
$cid = $dao->contact_id ;
|
||||
$birth_date_formatted = $dao->birth_date;
|
||||
|
||||
$values[$cid][$birthday_token] = $birth_date_formatted ;
|
||||
}
|
||||
|
||||
$dao->free();
|
||||
}
|
||||
}
|
||||
|
||||
next($tokens['dates']);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($tokens['communication'] )){
|
||||
$phone_token = 'communication.phone_all' ;
|
||||
|
||||
$email_token = 'communication.email_all' ;
|
||||
|
||||
require_once( 'utils/CommunicationTokenHelper.php');
|
||||
$commUtils = new CommunicationTokenHelper();
|
||||
|
||||
$commUtils->getTableOfPhones($contactIDs, $values, $phone_token );
|
||||
$commUtils->getTableOfEmails($contactIDs, $values, $email_token );
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!empty($tokens['greetings'])) {
|
||||
|
||||
$greetings_token_names = array(
|
||||
'greetings.joint_casual' => 'greetings.joint_casual',
|
||||
'greetings.joint_casual_firstname_lastname' => 'greetings.joint_casual_firstname_lastname',
|
||||
'greetings.joint_casual_nickname_only' => 'greetings.joint_casual_nickname_only',
|
||||
'greetings.joint_casual_firstname_only' => 'greetings.joint_casual_firstname_only',
|
||||
'greetings.solo_casual' => 'greetings.solo_casual',
|
||||
'greetings.solo_casual_nickname_only' => 'greetings.solo_casual_nickname_only',
|
||||
|
||||
'greetings.joint_formal' => 'greetings.joint_formal',
|
||||
'greetings.joint_formal_firstname' => 'greetings.joint_formal_firstname',
|
||||
|
||||
);
|
||||
if ( is_array( $contactIDs ) ) {
|
||||
|
||||
require_once ('utils/GreetingHelper.php');
|
||||
|
||||
$tmpGreetingHelper = new GreetingHelper();
|
||||
$prefixes = $tmpGreetingHelper->get_all_prefixes();
|
||||
$suffixes = $tmpGreetingHelper->get_all_suffixes();
|
||||
|
||||
$tmp_contactIds = $contactIDs ;
|
||||
// process all spouses using 'Spouse of' relationships.
|
||||
$household_id = '';
|
||||
$tmpGreetingHelper->process_spouses( $suffixes, $prefixes, $values, $contactIDs , $greetings_token_names, $household_id );
|
||||
$tmpGreetingHelper->process_households( $suffixes, $prefixes, $values, $contactIDs , $greetings_token_names);
|
||||
// process people not in households and without spouses.
|
||||
$tmpGreetingHelper->process_singles( $suffixes, $prefixes, $values, $greetings_token_names);
|
||||
|
||||
// process organizations
|
||||
$tmpGreetingHelper->process_organizations( $suffixes, $prefixes, $values, $greetings_token_names);
|
||||
|
||||
// Deal with 'solo' type greetings, no need to worry about relationships.
|
||||
$tmpGreetingHelper->process_solo_greetings( $suffixes, $prefixes, $values, $contactIDs , $greetings_token_names);
|
||||
|
||||
|
||||
// if any token is empty, use display_name of contact.
|
||||
// $tmpGreetingHelper->avoid_empty_tokens( $values, $contactIDs , $greetings_token_names);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!empty($tokens['communitynews'])){
|
||||
$website_host_name = $_SERVER['SERVER_NAME'];
|
||||
$ssl_in_use = $_SERVER['HTTPS'];
|
||||
if( strlen($ssl_in_use) > 0){
|
||||
$protocol = "https://";
|
||||
}else{
|
||||
$protocol = "http://";
|
||||
}
|
||||
/*
|
||||
$civi_url = CRM_Utils_System::url('civicrm/example', NULL, TRUE, NULL, FALSE);
|
||||
$website_host_name = parse_url( $civi_url, PHP_URL_HOST );
|
||||
|
||||
|
||||
$isSecure = false;
|
||||
if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
|
||||
$isSecure = true;
|
||||
}elseif ( ( !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') ||
|
||||
(!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && strtolower( $_SERVER['HTTP_X_FORWARDED_SSL']) == 'on') ) {
|
||||
$isSecure = true;
|
||||
}
|
||||
$protocol = $isSecure ? 'https://' : 'http://';
|
||||
*/
|
||||
|
||||
/*
|
||||
if ( array_key_exists( 'HTTPS', $_SERVER )){
|
||||
$ssl_in_use = $_SERVER['HTTPS'];
|
||||
if( strlen($ssl_in_use) > 0){
|
||||
$protocol = "https://";
|
||||
}else{
|
||||
$protocol = "http://";
|
||||
}
|
||||
}else{
|
||||
$protocol = "http://";
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
while( $cur_token_raw = current( $tokens['communitynews'] )){
|
||||
$tmp_key = key($tokens['communitynews']);
|
||||
@ -238,6 +456,36 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
|
||||
}
|
||||
|
||||
}else if( $partial_token == 'signpetition'){
|
||||
|
||||
# https://something.org/civicrm/petition/sign?reset=1&sid=IDNUMBER&{contact.checksum}&cid={contact.contact_id}
|
||||
$petition_id = $token_as_array[1];
|
||||
$partial_petition_link_url = CRM_Utils_System::url('civicrm/petition/sign', 'reset=1&sid=', TRUE, NULL, TRUE, TRUE);
|
||||
|
||||
|
||||
if( is_numeric( $petition_id )){
|
||||
|
||||
$params = array(
|
||||
'version' => 3,
|
||||
'sequential' => 1,
|
||||
'id' => $petition_id,
|
||||
);
|
||||
$result = civicrm_api('Survey', 'getsingle', $params);
|
||||
$link_label = $result['title'];
|
||||
|
||||
foreach ( $contactIDs as $cid ) {
|
||||
|
||||
$tmp_checksum = CRM_Contact_BAO_Contact_Utils::generateChecksum($cid);
|
||||
$full_petition_link = $partial_petition_link_url.$petition_id."&cs=".$tmp_checksum."&cid=".$cid;
|
||||
$tmp_petition_html = "<a href='".$full_petition_link."'>".$link_label."</a>";
|
||||
|
||||
$values[$cid][$token_to_fill] = $tmp_petition_html;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}else if( $partial_token == 'upcomingevents'){
|
||||
|
||||
@ -251,7 +499,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
if( is_numeric( $date_number) && ( $date_unit == 'day' || $date_unit == 'week' || $date_unit == 'month' )){
|
||||
// get event data
|
||||
$sql = "SELECT e.id , e.summary, e.title, e.registration_link_text,
|
||||
date_format( e.start_date, '%W %b %e at %l:%i %p' ) as start_date ,
|
||||
e.start_date as start_date ,
|
||||
if( e.is_online_registration = 1 AND
|
||||
( e.registration_end_date is null || now() <= e.registration_end_date ) AND
|
||||
( e.registration_start_date is null || now() >= e.registration_start_date ), '1', '0') as
|
||||
@ -301,7 +549,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
$summary_html = "";
|
||||
|
||||
}
|
||||
$tmp_event_html = $tmp_event_html."\n<br><br><a href='".$event_info_link_url.$eid."'>".$e_title."</a> on ".
|
||||
$tmp_event_html = $tmp_event_html."\n<br><br><a href='".$event_info_link_url.$eid."'>".$e_title."</a> ".
|
||||
$e_start_date.$register_html.$summary_html;
|
||||
}
|
||||
$dao->free();
|
||||
@ -323,13 +571,13 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
if( is_numeric( $token_event_id) ){
|
||||
// get event data
|
||||
$sql = "SELECT e.id , e.summary, e.title, e.registration_link_text,
|
||||
date_format( e.start_date, '%W %b %e at %l:%i %p' ) as start_date ,
|
||||
e.start_date as start_date ,
|
||||
if( e.is_online_registration = 1 AND
|
||||
( e.registration_end_date is null || now() <= e.registration_end_date ) AND
|
||||
( e.registration_start_date is null || now() >= e.registration_start_date ), '1', '0') as
|
||||
show_registration_link
|
||||
FROM civicrm_event e
|
||||
WHERE e.is_active = 1 AND e.is_public = 1 AND e.is_template <> 1 AND
|
||||
WHERE e.is_active = 1 AND e.is_template <> 1 AND
|
||||
e.start_date >= now() AND e.id = '".$token_event_id."'
|
||||
ORDER BY e.start_date";
|
||||
|
||||
@ -373,7 +621,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
$summary_html = "";
|
||||
|
||||
}
|
||||
$tmp_event_html = $tmp_event_html."\n<br><br>".$e_title." on ".
|
||||
$tmp_event_html = $tmp_event_html."\n<br><br>".$e_title." ".
|
||||
$e_start_date.$register_html.$summary_html;
|
||||
}
|
||||
$dao->free();
|
||||
@ -389,10 +637,36 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
$token_node_id = $token_as_array[1];
|
||||
|
||||
|
||||
$drupal_db = getUserFrameworkDatabaseName();
|
||||
// $drupal_db = getUserFrameworkDatabaseName();
|
||||
|
||||
if( is_numeric( $token_node_id) ){
|
||||
// get Drupal WebForm data for this node id.
|
||||
$dsql = "SELECT cforms.nid, node.title, ua.alias
|
||||
FROM {webform_civicrm_forms} cforms
|
||||
JOIN {node} node ON cforms.nid = node.nid AND node.status = 1
|
||||
LEFT JOIN {url_alias} ua ON cforms.nid = SUBSTRING( ua.source, 6 )
|
||||
AND ua.source LIKE 'node/%'
|
||||
WHERE node.nid = $token_node_id";
|
||||
|
||||
$dq_result = db_query( $dsql );
|
||||
foreach ($dq_result as $record) {
|
||||
$tmp_title = $record->title;
|
||||
$tmp_alias = $record->alias;
|
||||
$tmp_nid = $record->nid;
|
||||
if( strlen( $tmp_alias) > 0){
|
||||
//$partial_webform_link_url = $protocol.$website_host_name."/".$tmp_alias;
|
||||
$partial_webform_link_url = CRM_Utils_System::url($tmp_alias, "", TRUE, NULL, TRUE, TRUE);
|
||||
|
||||
}else{
|
||||
//$partial_webform_link_url = $protocol.$website_host_name."/node/".$tmp_nid;
|
||||
$partial_webform_link_url = CRM_Utils_System::url("/node/".$tmp_nid , "", TRUE, NULL, TRUE, TRUE);
|
||||
}
|
||||
$link_label = $tmp_title;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
$sql = "SELECT cforms.nid, node.title, ua.alias
|
||||
FROM $drupal_db.webform_civicrm_forms cforms
|
||||
JOIN $drupal_db.node ON cforms.nid = node.nid AND node.status = 1
|
||||
@ -413,11 +687,12 @@ function fancytokens_civicrm_tokens( &$tokens ){
|
||||
|
||||
}
|
||||
$dao->free();
|
||||
*/
|
||||
|
||||
foreach ( $contactIDs as $cid ) {
|
||||
|
||||
$tmp_checksum = CRM_Contact_BAO_Contact_Utils::generateChecksum($cid);
|
||||
$full_webform_link = $partial_webform_link_url."?"."cs=".$tmp_checksum."&cid=".$cid;
|
||||
$full_webform_link = $partial_webform_link_url."cs=".$tmp_checksum."&cid=".$cid;
|
||||
$tmp_webform_html = "<a href='".$full_webform_link."'>".$link_label."</a>";
|
||||
|
||||
$values[$cid][$token_to_fill] = $tmp_webform_html;
|
||||
|
19
info.xml
19
info.xml
@ -1,23 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<extension key="com.pogstone.fancytokens" type="module">
|
||||
<file>fancytokens</file>
|
||||
<name>Save time preparing newsletters: Fancy tokens for upcoming events, contribution pages, and forms</name>
|
||||
<description>Additional tokens for contribution pages, upcoming event lists, individual event registration pages, and stand-alone CiviCRM profiles. If Drupal WebForm is in use, then any webforms that use CiviCRM integration will also be available as a token. All hyperlinks include the recipient checksum as appropriate. To see the additional tokens, start composing an email and click 'insert tokens'.</description>
|
||||
<name>Save time preparing newsletters: Fancy tokens for upcoming events, petitions, contribution pages, and forms</name>
|
||||
<description>Additional tokens for contribution pages, upcoming event lists, petitions, individual event registration pages, and stand-alone CiviCRM profiles. If Drupal WebForm is in use, then any webforms that use CiviCRM integration will also be available as a token. All hyperlinks include the recipient checksum as appropriate. To see the additional tokens, start composing an email and click 'insert tokens'.</description>
|
||||
<urls>
|
||||
<url>http://pogstone.com</url>
|
||||
<url desc="Main Extension Page">https://civicrm.org/extensions/fancy-tokens</url>
|
||||
<url desc="Documentation">https://civicrm.org/extensions/fancy-tokens</url>
|
||||
<url desc="Support">https://github.com/sgladstone/com.pogstone.fancytokens/issues</url>
|
||||
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
|
||||
</urls>
|
||||
<license>AGPL-3.0</license>
|
||||
<maintainer>
|
||||
<author>Sarah Gladstone</author>
|
||||
<email>info@pogstone.com</email>
|
||||
<email>info@fountaintribe.com</email>
|
||||
</maintainer>
|
||||
<releaseDate>2015-05-24</releaseDate>
|
||||
<version>3.3</version>
|
||||
<releaseDate>2019-05-30</releaseDate>
|
||||
<version>5.1</version>
|
||||
<develStage>stable</develStage>
|
||||
<compatibility>
|
||||
<ver>4.4</ver>
|
||||
<ver>4.5</ver>
|
||||
<ver>4.6</ver>
|
||||
<ver>5.9</ver>
|
||||
</compatibility>
|
||||
<comments></comments>
|
||||
<civix>
|
||||
|
148
utils/CommunicationTokenHelper.php
Normal file
148
utils/CommunicationTokenHelper.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
class CommunicationTokenHelper{
|
||||
|
||||
function getTableOfPhones(&$contactIDs, &$values, &$token_needed ){
|
||||
|
||||
require_once('utils/CustomSearchTools.php');
|
||||
$tmp = new CustomSearchTools();
|
||||
$sql_cids = $tmp->convertArrayToSqlString($contactIDs);
|
||||
|
||||
$sql = "select ph.contact_id, ph.phone , ph.is_primary,
|
||||
lt.display_name as location_type_label,
|
||||
ov.label as phone_type_label
|
||||
FROM civicrm_phone ph
|
||||
LEFT JOIN civicrm_location_type lt ON ph.location_type_id = lt.id ,
|
||||
civicrm_option_value ov ,
|
||||
civicrm_option_group og
|
||||
WHERE ph.contact_id IN ( ".$sql_cids." )
|
||||
AND ph.phone_type_id = ov.value
|
||||
AND ov.option_group_id = og.id AND og.name = 'phone_type'
|
||||
ORDER BY ph.contact_id" ;
|
||||
// print "\n\n<br><br>sql: ".$sql;
|
||||
$dao =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray ) ;
|
||||
|
||||
$first = true;
|
||||
$prev_cid = "";
|
||||
|
||||
while($dao->fetch()){
|
||||
//print "\n\n<br>Inside while loop";
|
||||
|
||||
$cid = $dao->contact_id ;
|
||||
|
||||
$phone = $dao->phone;
|
||||
$is_primary = $dao->is_primary;
|
||||
$location_type_label = $dao->location_type_label;
|
||||
$phone_type_label = $dao->phone_type_label;
|
||||
|
||||
if(strcmp( $is_primary, '1') == 0 ){
|
||||
$is_primary_formatted = 'Yes';
|
||||
}else{
|
||||
$is_primary_formatted = 'No';
|
||||
}
|
||||
|
||||
if( strcmp($cid, $prev_cid ) <> 0 ){
|
||||
// First phone for this contact
|
||||
|
||||
$values[$cid][$token_needed] = "<table border=0 width='100%'><tr><th align=left>Number</th>
|
||||
<th align=left>Is Primary?</th><th align=left>Location</th><Th align=left>Phone Type</th></tr>";
|
||||
// wrap up token for prev. cid
|
||||
if( strcmp( $prev_cid, "") <> 0){
|
||||
|
||||
$values[$prev_cid][$token_needed] = $values[$prev_cid][$token_needed]."</table>";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// add the data for this child to this parent's token
|
||||
$values[$cid][$token_needed] = $values[$cid][$token_needed]."<tr><td>$phone</td>".
|
||||
"<td>$is_primary_formatted</td><td>$location_type_label</td><td>$phone_type_label</td></tr>";
|
||||
|
||||
|
||||
|
||||
|
||||
$prev_cid = $cid;
|
||||
}
|
||||
$dao->free();
|
||||
if( strcmp( $prev_cid, "") <> 0){
|
||||
|
||||
$values[$prev_cid][$token_needed] = $values[$prev_cid][$token_needed]."</table>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getTableOfEmails(&$contactIDs, &$values, &$token_needed){
|
||||
|
||||
|
||||
require_once('utils/CustomSearchTools.php');
|
||||
$tmp = new CustomSearchTools();
|
||||
$sql_cids = $tmp->convertArrayToSqlString($contactIDs);
|
||||
|
||||
$sql = "select em.contact_id, em.email , em.is_primary,
|
||||
lt.display_name as location_type_label
|
||||
FROM civicrm_email em
|
||||
LEFT JOIN civicrm_location_type lt ON em.location_type_id = lt.id
|
||||
WHERE em.contact_id IN ( ".$sql_cids." )
|
||||
ORDER BY em.contact_id" ;
|
||||
// print "\n\n<br><br>sql: ".$sql;
|
||||
$dao =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray ) ;
|
||||
|
||||
$first = true;
|
||||
$prev_cid = "";
|
||||
|
||||
while($dao->fetch()){
|
||||
//print "\n\n<br>Inside while loop";
|
||||
|
||||
$cid = $dao->contact_id ;
|
||||
|
||||
$email = $dao->email;
|
||||
$is_primary = $dao->is_primary;
|
||||
$location_type_label = $dao->location_type_label;
|
||||
|
||||
|
||||
if(strcmp( $is_primary, '1') == 0 ){
|
||||
$is_primary_formatted = 'Yes';
|
||||
}else{
|
||||
$is_primary_formatted = 'No';
|
||||
}
|
||||
|
||||
if( strcmp($cid, $prev_cid ) <> 0 ){
|
||||
// First phone for this contact
|
||||
|
||||
$values[$cid][$token_needed] = "<table border=0 width='100%'><tr><th align=left>Email</th>
|
||||
<th align=left>Is Primary?</th><th align=left>Location</th></tr>";
|
||||
// wrap up token for prev. cid
|
||||
if( strcmp( $prev_cid, "") <> 0){
|
||||
|
||||
$values[$prev_cid][$token_needed] = $values[$prev_cid][$token_needed]."</table>";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// add the data for this child to this parent's token
|
||||
$values[$cid][$token_needed] = $values[$cid][$token_needed]."<tr><td>$email</td>".
|
||||
"<td>$is_primary_formatted</td><td>$location_type_label</td></tr>";
|
||||
|
||||
|
||||
|
||||
|
||||
$prev_cid = $cid;
|
||||
}
|
||||
$dao->free();
|
||||
|
||||
if( strcmp( $prev_cid, "") <> 0){
|
||||
|
||||
$values[$prev_cid][$token_needed] = $values[$prev_cid][$token_needed]."</table>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
1144
utils/GreetingHelper.php
Normal file
1144
utils/GreetingHelper.php
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user