Ejemplo n.º 1
0
 /**
  * Store membership tokens on the static _tokens array.
  */
 protected static function _buildMembershipTokens()
 {
     $key = 'membership';
     if (!isset(self::$_tokens[$key]) || self::$_tokens[$key] == NULL) {
         $membershipTokens = array();
         $tokens = CRM_Core_SelectValues::membershipTokens();
         foreach ($tokens as $token => $dontCare) {
             $membershipTokens[] = substr($token, strpos($token, '.') + 1, -1);
         }
         self::$_tokens[$key] = $membershipTokens;
     }
 }
Ejemplo n.º 2
0
 /**
  * List available tokens for this form.
  *
  * @return array
  */
 public function listTokens()
 {
     $tokens = CRM_Core_SelectValues::contactTokens();
     $tokens = array_merge(CRM_Core_SelectValues::activityTokens(), $tokens);
     $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
     $tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens);
     $tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens);
     return $tokens;
 }
Ejemplo n.º 3
0
 /**
  * Function to build the  compose mail form
  *
  * @param   $form
  *
  * @return None
  * @access public
  */
 public static function commonCompose(&$form)
 {
     //get the tokens.
     $tokens = CRM_Core_SelectValues::contactTokens();
     //token selector for subject
     //CRM-5058
     $form->add('select', 'token3', ts('Insert Token'), $tokens, FALSE, array('size' => "5", 'multiple' => TRUE, 'onclick' => "return tokenReplText(this);"));
     $className = CRM_Utils_System::getClassName($form);
     if ($className == 'CRM_Mailing_Form_Upload') {
         $tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens);
     } elseif ($className == 'CRM_Admin_Form_ScheduleReminders') {
         $tokens = array_merge(CRM_Core_SelectValues::activityTokens(), $tokens);
         $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
         $tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens);
     } elseif ($className == 'CRM_Event_Form_ManageEvent_ScheduleReminders') {
         $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
     }
     //sorted in ascending order tokens by ignoring word case
     natcasesort($tokens);
     $form->assign('tokens', json_encode($tokens));
     $form->add('select', 'token1', ts('Insert Tokens'), $tokens, FALSE, array('size' => "5", 'multiple' => TRUE, 'onclick' => "return tokenReplText(this);"));
     $form->add('select', 'token2', ts('Insert Tokens'), $tokens, FALSE, array('size' => "5", 'multiple' => TRUE, 'onclick' => "return tokenReplHtml(this);"));
     $form->_templates = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
     if (!empty($form->_templates)) {
         $form->assign('templates', TRUE);
         $form->add('select', 'template', ts('Use Template'), array('' => ts('- select -')) + $form->_templates, FALSE, array('onChange' => "selectValue( this.value );"));
         $form->add('checkbox', 'updateTemplate', ts('Update Template'), NULL);
     }
     $form->add('checkbox', 'saveTemplate', ts('Save As New Template'), NULL, FALSE, array('onclick' => "showSaveDetails(this);"));
     $form->add('text', 'saveTemplateName', ts('Template Title'));
     //insert message Text by selecting "Select Template option"
     $form->add('textarea', 'text_message', ts('Plain-text format'), array('cols' => '80', 'rows' => '8', 'onkeyup' => "return verify(this)"));
     if ($className != 'CRM_SMS_Form_Upload' && $className != 'CRM_Contact_Form_Task_SMS' && $className != 'CRM_Contact_Form_Task_SMS') {
         $form->addWysiwyg('html_message', ts('HTML format'), array('cols' => '80', 'rows' => '8', 'onkeyup' => "return verify(this)"));
     }
 }
Ejemplo n.º 4
0
 /**
  * Build the  compose mail form.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function commonCompose(&$form)
 {
     //get the tokens.
     $tokens = CRM_Core_SelectValues::contactTokens();
     $className = CRM_Utils_System::getClassName($form);
     if ($className == 'CRM_Mailing_Form_Upload') {
         $tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens);
     } elseif ($className == 'CRM_Admin_Form_ScheduleReminders') {
         $tokens = array_merge(CRM_Core_SelectValues::activityTokens(), $tokens);
         $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
         $tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens);
     } elseif ($className == 'CRM_Event_Form_ManageEvent_ScheduleReminders') {
         $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
     }
     //sorted in ascending order tokens by ignoring word case
     $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
     $templates = array();
     $textFields = array('text_message' => ts('HTML Format'), 'sms_text_message' => ts('SMS Message'));
     $modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS');
     if ($className != 'CRM_SMS_Form_Upload' && $className != 'CRM_Contact_Form_Task_SMS' && $className != 'CRM_Contact_Form_Task_SMS') {
         $form->addWysiwyg('html_message', ts('HTML Format'), array('cols' => '80', 'rows' => '8', 'onkeyup' => "return verify(this)"));
         if ($className != 'CRM_Admin_Form_ScheduleReminders') {
             unset($modePrefixes['SMS']);
         }
     } else {
         unset($textFields['text_message']);
         unset($modePrefixes['Mail']);
     }
     //insert message Text by selecting "Select Template option"
     foreach ($textFields as $id => $label) {
         $prefix = NULL;
         if ($id == 'sms_text_message') {
             $prefix = "SMS";
             $form->assign('max_sms_length', CRM_SMS_Provider::MAX_SMS_CHAR);
         }
         $form->add('textarea', $id, $label, array('cols' => '80', 'rows' => '8', 'onkeyup' => "return verify(this, '{$prefix}')"));
     }
     foreach ($modePrefixes as $prefix) {
         if ($prefix == 'SMS') {
             $templates[$prefix] = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE, TRUE);
         } else {
             $templates[$prefix] = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
         }
         if (!empty($templates[$prefix])) {
             $form->assign('templates', TRUE);
             $form->add('select', "{$prefix}template", ts('Use Template'), array('' => ts('- select -')) + $templates[$prefix], FALSE, array('onChange' => "selectValue( this.value, '{$prefix}');"));
         }
         $form->add('checkbox', "{$prefix}updateTemplate", ts('Update Template'), NULL);
         $form->add('checkbox', "{$prefix}saveTemplate", ts('Save As New Template'), NULL, FALSE, array('onclick' => "showSaveDetails(this, '{$prefix}');"));
         $form->add('text', "{$prefix}saveTemplateName", ts('Template Title'));
     }
 }
Ejemplo n.º 5
0
 /**
  * list available tokens, at time of writing these were
  * {membership.id} => Membership ID
  * {membership.status} => Membership Status
  * {membership.type} => Membership Type
  * {membership.start_date} => Membership Start Date
  * {membership.join_date} => Membership Join Date
  * {membership.end_date} => Membership End Date
  * {membership.fee} => Membership Fee
  * @return Ambigous <NULL, multitype:string Ambigous <string, string> >
  */
 public function listTokens()
 {
     return CRM_Core_SelectValues::membershipTokens();
 }
 function postProcess()
 {
     $values = $this->_contactIds;
     $config = CRM_Core_Config::singleton();
     $msg_id = $this->_submitValues['message_template'];
     if (!empty($msg_id)) {
         $mysql = " SELECT * FROM veda_civicrm_wordmailmerge WHERE msg_template_id = %1";
         $params = array(1 => array($msg_id, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($mysql, $params);
         //$dao = CRM_Core_DAO::executeQuery($mysql);
         while ($dao->fetch()) {
             $fileId = $dao->file_id;
         }
         $sql = "SELECT * FROM civicrm_file WHERE id = %1";
         $params = array(1 => array($fileId, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         //$dao = CRM_Core_DAO::executeQuery($sql);
         while ($dao->fetch()) {
             $default['fileID'] = $dao->id;
             $default['mime_type'] = $dao->mime_type;
             $default['fileName'] = $dao->uri;
             $default['cleanName'] = CRM_Utils_File::cleanFileName($dao->uri);
             $default['fullPath'] = $config->customFileUploadDir . DIRECTORY_SEPARATOR . $dao->uri;
             $default['deleteURLArgs'] = CRM_Core_BAO_File::deleteURLArgs('civicrm_file', $msg_id, $dao->id);
         }
         $defaults[$dao->id] = $default;
         $this->assign('defaults', $defaults);
         $noofContact = count($this->_contactIds);
         require_once $config->extensionsDir . '/uk.co.vedaconsulting.module.wordmailmerge/tinybutstrong/tbs_class.php';
         require_once $config->extensionsDir . '/uk.co.vedaconsulting.module.wordmailmerge/tinybutstrong-opentbs/tbs_plugin_opentbs.php';
         $TBS = new clsTinyButStrong();
         // new instance of TBS
         $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
         // load the OpenTBS plugin
         $template = $default['fullPath'];
         // contactrows to check for duplicate address
         $contactrows = array();
         foreach ($values as $key => $value) {
             $SelectedcontactID = $values[$key];
             // get the details for all selected contacts
             list($contactDetails) = CRM_Utils_Token::getTokenDetails(array($SelectedcontactID), $this->_returnProperties, NULL, NULL, FALSE, $this->_allTokens);
             // populate contactrows array to check dupliacte address
             $contactrows[$SelectedcontactID] = $contactDetails[$SelectedcontactID];
         }
         // if merge_letter_for_same_address selected check for duplicate address
         if (isset($this->_submitValues['merge_letter_for_same_address']) && $this->_submitValues['merge_letter_for_same_address']) {
             CRM_Core_BAO_Address::mergeSameAddress($contactrows);
         }
         foreach ($values as $key => $value) {
             if ($key < $noofContact) {
                 $selectedCID = $values[$key];
                 $contactFormatted = array();
                 // if contact_id found in filtered contactrows array get contact details from contactrows
                 if (array_key_exists($selectedCID, $contactrows)) {
                     $contactFormatted[$selectedCID] = $contactrows[$selectedCID];
                     $membershipFormatted = array();
                     if ($this->_searchFrom == 'member' && isset($contactFormatted[$selectedCID]['membership_id'])) {
                         $membershipFormatted = CRM_Utils_Token::getMembershipTokenDetails($contactFormatted[$selectedCID]['membership_id']);
                     }
                     foreach ($this->_tokenMerge as $atKey => $atValue) {
                         // Replace hook tokens
                         $explodedTokenName = explode('.', $atValue['token_name']);
                         // this is fixed by assigning 'address_block' token into 'contact' token array // gopi@vedaconsulting.co.uk
                         //need to do proper fix seems token named as contact.address_block
                         // $atValue['token_name'] = ($atValue['token_name'] == 'address_block') ? 'contact.'.$atValue['token_name'] : $atValue['token_name'];
                         if (array_key_exists($atValue['token_name'], $contactFormatted[$selectedCID])) {
                             if (!empty($explodedTokenName[1]) && $explodedTokenName[0] != 'contact') {
                                 $vars[$key][$explodedTokenName[0]][$explodedTokenName[1]] = $contactFormatted[$selectedCID][$atValue['token_name']];
                             } else {
                                 $vars[$key][$atValue['token_name']] = $contactFormatted[$selectedCID][$atValue['token_name']];
                             }
                         } else {
                             if ($explodedTokenName[0] == 'membership') {
                                 $explodedTokenName[1] = $explodedTokenName[1] == 'membership_id' ? 'id' : $explodedTokenName[1];
                                 $vars[$key][$explodedTokenName[0]][$explodedTokenName[1]] = CRM_Utils_Token::getMembershipTokenReplacement($explodedTokenName[1], $membershipFormatted[$contactFormatted[$selectedCID]['membership_id']]);
                             } else {
                                 $vars[$key][$atValue['token_name']] = CRM_Utils_Token::getContactTokenReplacement($atValue['token_name'], $contactFormatted[$selectedCID], FALSE, FALSE);
                             }
                         }
                         //need to do proper fix, token_name.date seems not returning null value if not found
                         if ($explodedTokenName[0] == 'token_name' && !is_array($vars[$key]['token_name'])) {
                             $vars[$key][$atValue['token_name']] = '';
                         }
                     }
                     //to skip error, if by chance using membership token in 'find contact' search
                     if ($this->_searchFrom != 'member') {
                         foreach (CRM_Core_SelectValues::membershipTokens() as $token => $label) {
                             $token = str_replace(array('{', '}'), "", $token);
                             $tokenNames = explode('.', $token);
                             $vars[$key]['membership'][$tokenNames[1]] = $label;
                         }
                     }
                     foreach ($vars[$key] as $varKey => $varValue) {
                         $explodeValues = explode('.', $varKey);
                         if (isset($explodeValues[1]) && !empty($explodeValues[1])) {
                             $vars[$key][$explodeValues[0]][$explodeValues[1]] = $vars[$key][$varKey];
                             unset($vars[$key][$varKey]);
                         }
                     }
                     // blank lines removed while creating the address_block - gopi@vedaconsulting.co.uk
                     /*if (!empty($vars[$key]['contact']['address_block'])) {
                         $vars[$key]['contact']['address_block'] = str_replace('<br />', "", $vars[$key]['contact']['address_block']);
                       }*/
                     $TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8);
                     $TBS->MergeBlock(self::TOKEN_VAR_NAME, $vars);
                 }
             }
         }
         $output_file_name = 'CiviCRMWordExport.docx';
         $TBS->Show(OPENTBS_DOWNLOAD, $output_file_name);
         CRM_Utils_System::civiExit();
     }
     parent::postProcess();
 }