コード例 #1
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     $fv = $this->controller->exportValues($this->_name);
     $config = CRM_Core_Config::singleton();
     $locName = NULL;
     //get the address format sequence from the config file
     $mailingFormat = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'mailing_format');
     $sequence = CRM_Utils_Address::sequence($mailingFormat);
     foreach ($sequence as $v) {
         $address[$v] = 1;
     }
     if (array_key_exists('postal_code', $address)) {
         $address['postal_code_suffix'] = 1;
     }
     //build the returnproperties
     $returnProperties = array('display_name' => 1, 'contact_type' => 1);
     $mailingFormat = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'mailing_format');
     $mailingFormatProperties = array();
     if ($mailingFormat) {
         $mailingFormatProperties = self::getReturnProperties($mailingFormat);
         $returnProperties = array_merge($returnProperties, $mailingFormatProperties);
     }
     //we should not consider addressee for data exists, CRM-6025
     if (array_key_exists('addressee', $mailingFormatProperties)) {
         unset($mailingFormatProperties['addressee']);
     }
     $customFormatProperties = array();
     if (stristr($mailingFormat, 'custom_')) {
         foreach ($mailingFormatProperties as $token => $true) {
             if (substr($token, 0, 7) == 'custom_') {
                 if (empty($customFormatProperties[$token])) {
                     $customFormatProperties[$token] = $mailingFormatProperties[$token];
                 }
             }
         }
     }
     if (!empty($customFormatProperties)) {
         $returnProperties = array_merge($returnProperties, $customFormatProperties);
     }
     if (isset($fv['merge_same_address'])) {
         // we need first name/last name for summarising to avoid spillage
         $returnProperties['first_name'] = 1;
         $returnProperties['last_name'] = 1;
     }
     $individualFormat = FALSE;
     /*
      * CRM-8338: replace ids of household members with the id of their household
      * so we can merge labels by household.
      */
     if (isset($fv['merge_same_household'])) {
         $this->mergeContactIdsByHousehold();
         $individualFormat = TRUE;
     }
     //get the contacts information
     $params = array();
     if (!empty($fv['location_type_id'])) {
         $locType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
         $locName = $locType[$fv['location_type_id']];
         $location = array('location' => array("{$locName}" => $address));
         $returnProperties = array_merge($returnProperties, $location);
         $params[] = array('location_type', '=', array($fv['location_type_id'] => 1), 0, 0);
     } else {
         $returnProperties = array_merge($returnProperties, $address);
     }
     $rows = array();
     foreach ($this->_contactIds as $key => $contactID) {
         $params[] = array(CRM_Core_Form::CB_PREFIX . $contactID, '=', 1, 0, 0);
     }
     // fix for CRM-2651
     if (!empty($fv['do_not_mail'])) {
         $params[] = array('do_not_mail', '=', 0, 0, 0);
     }
     // fix for CRM-2613
     $params[] = array('is_deceased', '=', 0, 0, 0);
     $custom = array();
     foreach ($returnProperties as $name => $dontCare) {
         $cfID = CRM_Core_BAO_CustomField::getKeyID($name);
         if ($cfID) {
             $custom[] = $cfID;
         }
     }
     //get the total number of contacts to fetch from database.
     $numberofContacts = count($this->_contactIds);
     $query = new CRM_Contact_BAO_Query($params, $returnProperties);
     $details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts);
     $messageToken = CRM_Utils_Token::getTokens($mailingFormat);
     // also get all token values
     CRM_Utils_Hook::tokenValues($details[0], $this->_contactIds, NULL, $messageToken, 'CRM_Contact_Form_Task_Label');
     $tokens = array();
     CRM_Utils_Hook::tokens($tokens);
     $tokenFields = array();
     foreach ($tokens as $category => $catTokens) {
         foreach ($catTokens as $token => $tokenName) {
             $tokenFields[] = $token;
         }
     }
     foreach ($this->_contactIds as $value) {
         foreach ($custom as $cfID) {
             if (isset($details[0][$value]["custom_{$cfID}"])) {
                 $details[0][$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::getDisplayValue($details[0][$value]["custom_{$cfID}"], $cfID, $details[1]);
             }
         }
         $contact = CRM_Utils_Array::value($value, $details['0']);
         if (is_a($contact, 'CRM_Core_Error')) {
             return NULL;
         }
         // we need to remove all the "_id"
         unset($contact['contact_id']);
         if ($locName && !empty($contact[$locName])) {
             // If location type is not primary, $contact contains
             // one more array as "$contact[$locName] = array( values... )"
             if (!$this->tokenIsFound($contact, $mailingFormatProperties, $tokenFields)) {
                 continue;
             }
             unset($contact[$locName]);
             if (!empty($contact['county_id'])) {
                 unset($contact['county_id']);
             }
             foreach ($contact as $field => $fieldValue) {
                 $rows[$value][$field] = $fieldValue;
             }
             $valuesothers = array();
             $paramsothers = array('contact_id' => $value);
             $valuesothers = CRM_Core_BAO_Location::getValues($paramsothers, $valuesothers);
             if (!empty($fv['location_type_id'])) {
                 foreach ($valuesothers as $vals) {
                     if (CRM_Utils_Array::value('location_type_id', $vals) == CRM_Utils_Array::value('location_type_id', $fv)) {
                         foreach ($vals as $k => $v) {
                             if (in_array($k, array('email', 'phone', 'im', 'openid'))) {
                                 if ($k == 'im') {
                                     $rows[$value][$k] = $v['1']['name'];
                                 } else {
                                     $rows[$value][$k] = $v['1'][$k];
                                 }
                                 $rows[$value][$k . '_id'] = $v['1']['id'];
                             }
                         }
                     }
                 }
             }
         } else {
             if (!$this->tokenIsFound($contact, $mailingFormatProperties, $tokenFields)) {
                 continue;
             }
             if (!empty($contact['addressee_display'])) {
                 $contact['addressee_display'] = trim($contact['addressee_display']);
             }
             if (!empty($contact['addressee'])) {
                 $contact['addressee'] = $contact['addressee_display'];
             }
             // now create the rows for generating mailing labels
             foreach ($contact as $field => $fieldValue) {
                 $rows[$value][$field] = $fieldValue;
             }
         }
     }
     if (isset($fv['merge_same_address'])) {
         $this->mergeSameAddress($rows);
         $individualFormat = TRUE;
     }
     // format the addresses according to CIVICRM_ADDRESS_FORMAT (CRM-1327)
     foreach ($rows as $id => $row) {
         if ($commMethods = CRM_Utils_Array::value('preferred_communication_method', $row)) {
             $val = array_filter(explode(CRM_Core_DAO::VALUE_SEPARATOR, $commMethods));
             $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
             $temp = array();
             foreach ($val as $vals) {
                 $temp[] = $comm[$vals];
             }
             $row['preferred_communication_method'] = implode(', ', $temp);
         }
         $row['id'] = $id;
         $formatted = CRM_Utils_Address::format($row, 'mailing_format', FALSE, TRUE, $individualFormat, $tokenFields);
         // CRM-2211: UFPDF doesn't have bidi support; use the PECL fribidi package to fix it.
         // On Ubuntu (possibly Debian?) be aware of http://pecl.php.net/bugs/bug.php?id=12366
         // Due to FriBidi peculiarities, this can't be called on
         // a multi-line string, hence the explode+implode approach.
         if (function_exists('fribidi_log2vis')) {
             $lines = explode("\n", $formatted);
             foreach ($lines as $i => $line) {
                 $lines[$i] = fribidi_log2vis($line, FRIBIDI_AUTO, FRIBIDI_CHARSET_UTF8);
             }
             $formatted = implode("\n", $lines);
         }
         $rows[$id] = array($formatted);
     }
     //call function to create labels
     self::createLabel($rows, $fv['label_name']);
     CRM_Utils_System::civiExit(1);
 }
コード例 #2
0
ファイル: 004.php プロジェクト: badlamer/hhvm
<?php

error_reporting(E_ALL);
$a = fribidi_log2vis(null, FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$b = fribidi_log2vis(false, FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$c = fribidi_log2vis(true, FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$d = fribidi_log2vis(0, FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$e = fribidi_log2vis(1, FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$f = fribidi_log2vis('', FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$g = fribidi_log2vis("", FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
var_dump(array($a, $b, $c, $d, $e, $f, $g));
コード例 #3
0
ファイル: Label.php プロジェクト: bhirsch/civicrm
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return void
  */
 public function postProcess()
 {
     $fv = $this->controller->exportValues($this->_name);
     $config =& CRM_Core_Config::singleton();
     $locName = null;
     //get the address format sequence from the config file
     require_once 'CRM/Core/BAO/Preferences.php';
     $sequence = CRM_Core_BAO_Preferences::value('mailing_sequence');
     foreach ($sequence as $v) {
         $address[$v] = 1;
     }
     if (array_key_exists('postal_code', $address)) {
         $address['postal_code_suffix'] = 1;
     }
     //build the returnproperties
     $returnProperties = array('display_name' => 1);
     $mailingFormat = CRM_Core_BAO_Preferences::value('mailing_format');
     $mailingFormatProperties = array();
     if ($mailingFormat) {
         $mailingFormatProperties = self::getReturnProperties($mailingFormat);
         $returnProperties = array_merge($returnProperties, $mailingFormatProperties);
     }
     $customFormatProperties = array();
     if (stristr($mailingFormat, 'custom_')) {
         foreach ($mailingFormatProperties as $token => $true) {
             if (substr($token, 0, 7) == 'custom_') {
                 if (!CRM_Utils_Array::value($token, $customFormatProperties)) {
                     $customFormatProperties[$token] = $mailingFormatProperties[$token];
                 }
             }
         }
     }
     if (!empty($customFormatProperties)) {
         $returnProperties = array_merge($returnProperties, $customFormatProperties);
     }
     //get the contacts information
     $params = array();
     if (CRM_Utils_Array::value('location_type_id', $fv)) {
         $locType = CRM_Core_PseudoConstant::locationType();
         $locName = $locType[$fv['location_type_id']];
         $location = array('location' => array("{$locName}" => $address));
         $returnProperties = array_merge($returnProperties, $location);
         $params[] = array('location_type', '=', array($fv['location_type_id'] => 1), 0, 0);
     } else {
         $returnProperties = array_merge($returnProperties, $address);
     }
     $rows = array();
     foreach ($this->_contactIds as $key => $contactID) {
         $params[] = array(CRM_Core_Form::CB_PREFIX . $contactID, '=', 1, 0, 0);
     }
     // fix for CRM-2651
     if (CRM_Utils_Array::value('do_not_mail', $fv)) {
         $params[] = array('do_not_mail', '=', 0, 0, 0);
     }
     // fix for CRM-2613
     $params[] = array('is_deceased', '=', 0, 0, 0);
     $custom = array();
     foreach ($returnProperties as $name => $dontCare) {
         $cfID = CRM_Core_BAO_CustomField::getKeyID($name);
         if ($cfID) {
             $custom[] = $cfID;
         }
     }
     //get the total number of contacts to fetch from database.
     $numberofContacts = count($this->_contactIds);
     require_once 'CRM/Contact/BAO/Query.php';
     $query =& new CRM_Contact_BAO_Query($params, $returnProperties);
     $details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts);
     // also get all token values
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::tokenValues($details[0], $this->_contactIds);
     $tokens = array();
     CRM_Utils_Hook::tokens($tokens);
     $tokenFields = array();
     foreach ($tokens as $category => $catTokens) {
         foreach ($catTokens as $token) {
             $tokenFields[] = $token;
         }
     }
     foreach ($this->_contactIds as $value) {
         foreach ($custom as $cfID) {
             if (isset($details[0][$value]["custom_{$cfID}"])) {
                 $details[0][$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::getDisplayValue($details[0][$value]["custom_{$cfID}"], $cfID, $details[1]);
             }
         }
         $contact = CRM_Utils_Array::value($value, $details['0']);
         if (is_a($contact, 'CRM_Core_Error')) {
             return null;
         }
         // we need to remove all the "_id"
         unset($contact['contact_id']);
         if ($locName && CRM_Utils_Array::value($locName, $contact)) {
             // If location type is not primary, $contact contains
             // one more array as "$contact[$locName] = array( values... )"
             $found = false;
             // we should replace all the tokens that are set in mailing label format
             foreach ($mailingFormatProperties as $key => $dontCare) {
                 if (CRM_Utils_Array::value($key, $contact)) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 continue;
             }
             unset($contact[$locName]);
             if (CRM_Utils_Array::value('county_id', $contact)) {
                 unset($contact['county_id']);
             }
             foreach ($contact as $field => $fieldValue) {
                 $rows[$value][$field] = $fieldValue;
             }
             $valuesothers = array();
             $paramsothers = array('contact_id' => $value);
             require_once 'CRM/Core/BAO/Location.php';
             $valuesothers = CRM_Core_BAO_Location::getValues($paramsothers, $valuesothers);
             if (CRM_Utils_Array::value('location_type_id', $fv)) {
                 foreach ($valuesothers as $vals) {
                     if ($vals['location_type_id'] == CRM_Utils_Array::value('location_type_id', $fv)) {
                         foreach ($vals as $k => $v) {
                             if (in_array($k, array('email', 'phone', 'im', 'openid'))) {
                                 if ($k == 'im') {
                                     $rows[$value][$k] = $v['1']['name'];
                                 } else {
                                     $rows[$value][$k] = $v['1'][$k];
                                 }
                                 $rows[$value][$k . '_id'] = $v['1']['id'];
                             }
                         }
                     }
                 }
             }
         } else {
             $found = false;
             // we should replace all the tokens that are set in mailing label format
             foreach ($mailingFormatProperties as $key => $dontCare) {
                 if (CRM_Utils_Array::value($key, $contact)) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 continue;
             }
             if (CRM_Utils_Array::value('addressee', $contact)) {
                 $contact['addressee'] = $contact['addressee_display'];
             }
             // now create the rows for generating mailing labels
             foreach ($contact as $field => $fieldValue) {
                 $rows[$value][$field] = $fieldValue;
             }
         }
     }
     $individualFormat = false;
     if (isset($fv['merge_same_address'])) {
         $this->mergeSameAddress($rows);
         $individualFormat = true;
     }
     // format the addresses according to CIVICRM_ADDRESS_FORMAT (CRM-1327)
     require_once 'CRM/Utils/Address.php';
     foreach ($rows as $id => $row) {
         if ($commMethods = CRM_Utils_Array::value('preferred_communication_method', $row)) {
             require_once 'CRM/Core/PseudoConstant.php';
             $val = array_filter(explode(CRM_Core_DAO::VALUE_SEPARATOR, $commMethods));
             $comm = CRM_Core_PseudoConstant::pcm();
             $temp = array();
             foreach ($val as $vals) {
                 $temp[] = $comm[$vals];
             }
             $row['preferred_communication_method'] = implode(', ', $temp);
         }
         $row['id'] = $id;
         $formatted = CRM_Utils_Address::format($row, 'mailing_format', false, true, $individualFormat, $tokenFields);
         // CRM-2211: UFPDF doesn't have bidi support; use the PECL fribidi package to fix it.
         // On Ubuntu (possibly Debian?) be aware of http://pecl.php.net/bugs/bug.php?id=12366
         // Due to FriBidi peculiarities, this can't be called on
         // a multi-line string, hence the explode+implode approach.
         if (function_exists('fribidi_log2vis')) {
             $lines = explode("\n", $formatted);
             foreach ($lines as $i => $line) {
                 $lines[$i] = fribidi_log2vis($line, FRIBIDI_AUTO, FRIBIDI_CHARSET_UTF8);
             }
             $formatted = implode("\n", $lines);
         }
         $rows[$id] = array($formatted);
     }
     //call function to create labels
     self::createLabel($rows, $fv['label_id']);
     exit(1);
 }
コード例 #4
0
ファイル: 005.php プロジェクト: badlamer/hhvm
<?php

error_reporting(E_ALL);
$a = fribidi_log2vis("ABC def", FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$b = fribidi_log2vis("ABC def", FRIBIDI_LTR, FRIBIDI_CHARSET_CAP_RTL);
$c = fribidi_log2vis("ABC def", FRIBIDI_RTL, FRIBIDI_CHARSET_CAP_RTL);
$d = fribidi_log2vis("ABC def", FRIBIDI_WLTR, FRIBIDI_CHARSET_CAP_RTL);
$e = fribidi_log2vis("ABC def", FRIBIDI_WRTL, FRIBIDI_CHARSET_CAP_RTL);
var_dump(array($a, $b, $c, $d, $e));
$a = fribidi_log2vis("abc DEF", FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$b = fribidi_log2vis("abc DEF", FRIBIDI_LTR, FRIBIDI_CHARSET_CAP_RTL);
$c = fribidi_log2vis("abc DEF", FRIBIDI_RTL, FRIBIDI_CHARSET_CAP_RTL);
$d = fribidi_log2vis("abc DEF", FRIBIDI_WLTR, FRIBIDI_CHARSET_CAP_RTL);
$e = fribidi_log2vis("abc DEF", FRIBIDI_WRTL, FRIBIDI_CHARSET_CAP_RTL);
var_dump(array($a, $b, $c, $d, $e));
$a = fribidi_log2vis("123 456", FRIBIDI_AUTO, FRIBIDI_CHARSET_CAP_RTL);
$b = fribidi_log2vis("123 456", FRIBIDI_LTR, FRIBIDI_CHARSET_CAP_RTL);
$c = fribidi_log2vis("123 456", FRIBIDI_RTL, FRIBIDI_CHARSET_CAP_RTL);
$d = fribidi_log2vis("123 456", FRIBIDI_WLTR, FRIBIDI_CHARSET_CAP_RTL);
$e = fribidi_log2vis("123 456", FRIBIDI_WRTL, FRIBIDI_CHARSET_CAP_RTL);
var_dump(array($a, $b, $c, $d, $e));