Compare commits

..

43 Commits
3.4 ... master

Author SHA1 Message Date
rt
03a799a290 Update 'fancytokens.php'
502: 	            $sql = "SELECT e.id , e.summary,  e.title, e.registration_link_text, 
503: +	             e.start_date as start_date  ,
505: 	             if( e.is_online_registration = 1 AND

576: 	            $sql = "SELECT e.id , e.summary,  e.title, e.registration_link_text, 
e.start_date as start_date  ,
2019-10-30 08:41:13 +00:00
rt
adc61f2d58 Update 'fancytokens.php'
Changed format of date and texts
Résumé des changements
31:   		$e_start_date = $dao->start_date;
32: -  		$label = 'Registration Page: '.$e_title.' on '.$e_start_date.' (id: '.$e_id.')  :: Events'; 
33: +  		$label = 'Registration Page: '.$e_title.' '.$e_start_date.' (id: '.$e_id.')  :: Events'; 
34:   		$key = 'communitynews.event_registrationpage___'.$e_id ;

502: 	            $sql = "SELECT e.id , e.summary,  e.title, e.registration_link_text, 
503: -	             date_format( e.start_date, '%W %b %e at %l:%i %p' ) as start_date  ,
504: +	             date_format( e.start_date, '%d/%m/%Y à %Hh%i' ) as start_date  ,
505: 	             if( e.is_online_registration = 1 AND

553:   		     	} 
554: -  		     	$tmp_event_html = $tmp_event_html."\n<br><br><a href='".$event_info_link_url.$eid."'>".$e_title."</a> on ".
555: +  		     	$tmp_event_html = $tmp_event_html."\n<br><br><a href='".$event_info_link_url.$eid."'>".$e_title."</a> ".
556:   		     		$e_start_date.$register_html.$summary_html;

576: 	            $sql = "SELECT e.id , e.summary,  e.title, e.registration_link_text, 
577: -	             date_format( e.start_date, '%W %b %e at %l:%i %p' ) as start_date  ,
578: +	             date_format( e.start_date, '%d/%m/%Y à %Hh%i' ) as start_date  ,
579: 	             if( e.is_online_registration = 1 AND

627:   		     	} 
628: -  		     	$tmp_event_html = $tmp_event_html."\n<br><br>".$e_title." on ".
629: +  		     	$tmp_event_html = $tmp_event_html."\n<br><br>".$e_title." ".
630:   		     		$e_start_date.$register_html.$summary_html;
2019-10-30 08:33:15 +00:00
Sarah Poger Gladstone
2bbbf9aa43
Update info.xml 2019-05-30 00:30:02 -04:00
Sarah Poger Gladstone
98a9042f94
Update README.md 2019-05-30 00:28:33 -04:00
Sarah Poger Gladstone
2cf7197082
Update fancytokens.php 2019-05-30 00:25:18 -04:00
Sarah Poger Gladstone
6166e0b41e
Update fancytokens.php 2019-05-29 23:54:25 -04:00
Sarah Poger Gladstone
03c517e3aa
Update fancytokens.php 2019-05-29 23:39:59 -04:00
Sarah Poger Gladstone
0ad2f42fa2
updated version info 2019-05-28 06:41:58 -04:00
Sarah Poger Gladstone
7cb8bff32c
fixed SSL checks 2019-05-28 06:37:55 -04:00
Sarah Poger Gladstone
3422d6b46c
fixed gender labels 2019-05-28 06:06:22 -04:00
Sarah Poger Gladstone
b64cef5627
added petition logic 2019-05-28 06:00:29 -04:00
Sarah Poger Gladstone
e1d93ac1cf
fixed typo 2019-05-28 04:51:10 -04:00
Sarah Poger Gladstone
13f10399e9
api call for checksum expiration 2019-05-28 04:39:35 -04:00
Sarah Poger Gladstone
3802edc486
added logic for checksum expiration date token 2019-05-28 04:36:29 -04:00
Sarah Poger Gladstone
4c192235e7
fixed typo 2019-05-27 16:28:48 -04:00
Sarah Poger Gladstone
de6827f80b
fixed missing semicolon 2019-05-27 16:27:41 -04:00
Sarah Poger Gladstone
776f666d94
updated version info 2019-05-27 16:14:53 -04:00
Sarah Poger Gladstone
35485af11d
updated prefix behavior, handling of private events 2019-05-27 09:38:50 -04:00
Sarah Poger Gladstone
e72264f058
updated behavior for prefixes related to gender
When the gender is not 'Male' or 'Female' for a contact without a prefix, no assumptions are made. If the greeting token that needs "Mr. " or "Dr." or "Ms." is used in this case, the unknown prefix will be "UNKNOWN PREFIX"
2019-05-27 09:37:25 -04:00
Sarah Poger Gladstone
ec1e8314c7
Allow tokens of type event_registrationpage to work for private events 2019-05-27 09:22:10 -04:00
sgladstone
4333b6ca8e added communication tokens (ie all emails, all phone numbers) 2016-09-05 15:08:57 -04:00
Sarah Gladstone
32bfadcb66 updated date 2016-08-26 15:42:28 -04:00
Sarah Gladstone
1d79d93af5 updated urls 2016-08-26 15:41:58 -04:00
Sarah Gladstone
797a94eccb updated code 2016-08-26 15:40:17 -04:00
Sarah Gladstone
39d7d3ff75 updated code 2016-08-26 13:22:36 -04:00
Sarah Gladstone
59a2ab2bf5 updated version 2016-08-26 10:28:48 -04:00
Sarah Gladstone
9488f1a0b3 fixed warnings 2016-08-26 10:27:05 -04:00
Sarah Gladstone
99838677b7 fixed typo 2016-08-26 09:57:11 -04:00
Sarah Gladstone
27702f4d80 updated code 2016-08-26 09:49:51 -04:00
Sarah Gladstone
f07759184e added description of tokens 2016-08-26 09:47:57 -04:00
Sarah Gladstone
d60bdb098b added tokens for "greetings" for couples, housholds, and single people. 2016-08-26 09:29:35 -04:00
sgladstone
b17dd2d8b4 Updated version info for CiviCRM 4.7.x 2016-07-24 18:23:10 -04:00
Sarah Poger Gladstone
2d003153df Update .project 2016-07-24 18:18:52 -04:00
Sarah Poger Gladstone
f2247b7c29 fixed extra text 2016-07-24 17:48:47 -04:00
Sarah Poger Gladstone
bcbadc64fe Create .buildpath 2016-07-24 17:36:09 -04:00
Sarah Poger Gladstone
8b88267991 Create .project 2016-07-24 17:35:26 -04:00
Sarah Poger Gladstone
ce057368e2 updated version information 2016-05-20 09:51:56 -04:00
Sarah Poger Gladstone
b9cca6e139 Merge pull request #12 from PalanteJon/fix-array-ptypes
Fix in_array and explode warnings
2016-05-20 09:49:35 -04:00
Jon goldberg
f123890b01 Fix in_array and explode warnings 2016-05-20 00:10:22 -04:00
Sarah Poger Gladstone
7103382fec Update fancytokens.php 2016-04-02 13:15:00 -04:00
Sarah Poger Gladstone
5845e4d512 Update info.xml 2015-12-06 06:04:47 -05:00
Sarah Poger Gladstone
59b353ed8c Merge pull request #9 from colemanw/patch-1
Prevent possible fatal error
2015-12-04 20:56:54 -05:00
colemanw
fcf17df571 Prevent possible fatal error 2015-11-21 15:06:00 -05:00
7 changed files with 1633 additions and 50 deletions

5
.buildpath Normal file
View 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
View 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>

View File

@ -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. 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: 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. 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. (Note: The only version of Drupal this has been tested with is Drupal7.) 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.

View File

@ -29,7 +29,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
$e_id = $dao->id; $e_id = $dao->id;
$e_title = $dao->title; $e_title = $dao->title;
$e_start_date = $dao->start_date; $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 ; $key = 'communitynews.event_registrationpage___'.$e_id ;
$tokens['communitynews'][$key] = $label; $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. // Get all active profiles and create tokens for the ones that can be stand-alone.
$params = array( $params = array(
@ -78,8 +99,9 @@ function fancytokens_civicrm_tokens( &$tokens ){
$p_type = ""; $p_type = "";
if( isset( $cur['group_type'])){ if( isset( $cur['group_type'])){
$p_type = $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 $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 ) )) { 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 ) )) {
@ -91,6 +113,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
} }
} }
}
} }
@ -100,7 +123,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
//print "<br><br>"; //print "<br><br>";
//print_r($config); //print_r($config);
if ($config->userSystem->is_drupal){ if ($config->userSystem->is_drupal){
if( module_exists( "webform") && module_exists( "webform_civicrm")){ if (function_exists("module_exists") && module_exists("webform_civicrm")) {
//$drupal_db = getUserFrameworkDatabaseName(); //$drupal_db = getUserFrameworkDatabaseName();
//$sql = "SELECT cforms.nid, node.title FROM $drupal_db.webform_civicrm_forms cforms //$sql = "SELECT cforms.nid, node.title FROM $drupal_db.webform_civicrm_forms cforms
@ -123,26 +146,52 @@ function fancytokens_civicrm_tokens( &$tokens ){
} }
/*$dao =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray ) ;
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(){ function getUserFrameworkDatabaseName(){
// ['userFrameworkDSN'] => mysql://dev1_username:mypassword@localhost/dev1_main?new_link=true // ['userFrameworkDSN'] => mysql://dev1_username:mypassword@localhost/dev1_main?new_link=true
@ -164,14 +213,166 @@ function fancytokens_civicrm_tokens( &$tokens ){
function fancytokens_civicrm_tokenValues( &$values, &$contactIDs, $job = null, $tokens = array(), $context = null) { 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'])){ if(!empty($tokens['communitynews'])){
$website_host_name = $_SERVER['SERVER_NAME']; /*
$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']; $ssl_in_use = $_SERVER['HTTPS'];
if( strlen($ssl_in_use) > 0){ if( strlen($ssl_in_use) > 0){
$protocol = "https://"; $protocol = "https://";
}else{ }else{
$protocol = "http://"; $protocol = "http://";
} }
}else{
$protocol = "http://";
}
*/
while( $cur_token_raw = current( $tokens['communitynews'] )){ while( $cur_token_raw = current( $tokens['communitynews'] )){
$tmp_key = key($tokens['communitynews']); $tmp_key = key($tokens['communitynews']);
@ -255,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'){ }else if( $partial_token == 'upcomingevents'){
@ -268,7 +499,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
if( is_numeric( $date_number) && ( $date_unit == 'day' || $date_unit == 'week' || $date_unit == 'month' )){ if( is_numeric( $date_number) && ( $date_unit == 'day' || $date_unit == 'week' || $date_unit == 'month' )){
// get event data // get event data
$sql = "SELECT e.id , e.summary, e.title, e.registration_link_text, $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 if( e.is_online_registration = 1 AND
( e.registration_end_date is null || now() <= e.registration_end_date ) 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 ( e.registration_start_date is null || now() >= e.registration_start_date ), '1', '0') as
@ -318,7 +549,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
$summary_html = ""; $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; $e_start_date.$register_html.$summary_html;
} }
$dao->free(); $dao->free();
@ -340,13 +571,13 @@ function fancytokens_civicrm_tokens( &$tokens ){
if( is_numeric( $token_event_id) ){ if( is_numeric( $token_event_id) ){
// get event data // get event data
$sql = "SELECT e.id , e.summary, e.title, e.registration_link_text, $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 if( e.is_online_registration = 1 AND
( e.registration_end_date is null || now() <= e.registration_end_date ) 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 ( e.registration_start_date is null || now() >= e.registration_start_date ), '1', '0') as
show_registration_link show_registration_link
FROM civicrm_event e 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."' e.start_date >= now() AND e.id = '".$token_event_id."'
ORDER BY e.start_date"; ORDER BY e.start_date";
@ -390,7 +621,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
$summary_html = ""; $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; $e_start_date.$register_html.$summary_html;
} }
$dao->free(); $dao->free();
@ -423,9 +654,12 @@ function fancytokens_civicrm_tokens( &$tokens ){
$tmp_alias = $record->alias; $tmp_alias = $record->alias;
$tmp_nid = $record->nid; $tmp_nid = $record->nid;
if( strlen( $tmp_alias) > 0){ if( strlen( $tmp_alias) > 0){
$partial_webform_link_url = $protocol.$website_host_name."/".$tmp_alias; //$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{ }else{
$partial_webform_link_url = $protocol.$website_host_name."/node/".$tmp_nid; //$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; $link_label = $tmp_title;
@ -458,7 +692,7 @@ function fancytokens_civicrm_tokens( &$tokens ){
foreach ( $contactIDs as $cid ) { foreach ( $contactIDs as $cid ) {
$tmp_checksum = CRM_Contact_BAO_Contact_Utils::generateChecksum($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>"; $tmp_webform_html = "<a href='".$full_webform_link."'>".$link_label."</a>";
$values[$cid][$token_to_fill] = $tmp_webform_html; $values[$cid][$token_to_fill] = $tmp_webform_html;

View File

@ -1,23 +1,24 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<extension key="com.pogstone.fancytokens" type="module"> <extension key="com.pogstone.fancytokens" type="module">
<file>fancytokens</file> <file>fancytokens</file>
<name>Save time preparing newsletters: Fancy tokens for upcoming events, contribution pages, and forms</name> <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, 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> <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> <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> </urls>
<license>AGPL-3.0</license> <license>AGPL-3.0</license>
<maintainer> <maintainer>
<author>Sarah Gladstone</author> <author>Sarah Gladstone</author>
<email>info@pogstone.com</email> <email>info@fountaintribe.com</email>
</maintainer> </maintainer>
<releaseDate>2015-05-24</releaseDate> <releaseDate>2019-05-30</releaseDate>
<version>3.4</version> <version>5.1</version>
<develStage>stable</develStage> <develStage>stable</develStage>
<compatibility> <compatibility>
<ver>4.4</ver> <ver>5.9</ver>
<ver>4.5</ver>
<ver>4.6</ver>
</compatibility> </compatibility>
<comments></comments> <comments></comments>
<civix> <civix>

View 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

File diff suppressed because it is too large Load Diff