예제 #1
0
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     // get the callback, module and activity id
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $dao = new CRM_Core_DAO_ActivityHistory();
     $dao->activity_id = $id;
     $dao->activity_type = ts('SMS Sent');
     if ($dao->find(TRUE)) {
         $cid = $dao->entity_id;
     }
     $dao = new CRM_SMS_DAO_History();
     $dao->id = $id;
     if ($dao->find(TRUE)) {
         $this->assign('fromName', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $dao->contact_id, 'display_name'));
         $this->assign('toName', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name'));
         $this->assign('sentDate', $dao->sent_date);
         $this->assign('message', $dao->message);
         // get the display name and images for the contact
         list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($dao->contact_id);
         CRM_Utils_System::setTitle($contactImage . ' ' . $displayName);
         // also add the cid params to the Menu array
         CRM_Core_Menu::addParam('cid', $cid);
     }
     return parent::run();
 }
예제 #2
0
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     // get the callback, module and activity id
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse');
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $dao = new CRM_Core_DAO_ActivityHistory();
     $dao->activity_id = $id;
     $dao->activity_type = ts('Email Sent');
     if ($dao->find(true)) {
         $cid = $dao->entity_id;
     }
     $dao = new CRM_Core_DAO_EmailHistory();
     $dao->id = $id;
     if ($dao->find(true)) {
         // get the display name and email for the contact
         list($toContactName, $toContactEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($cid);
         if (!trim($toContactName)) {
             $toContactName = $toContactEmail;
         }
         if (trim($toContactEmail)) {
             $toContactName = "\"{$toContactName}\" <{$toContactEmail}>";
         }
         $this->assign('toName', $toContactName);
         // get the display name and email for the contact
         list($fromContactName, $fromContactEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($dao->contact_id);
         if (!trim($fromContactEmail)) {
             CRM_Core_Error::statusBounce(ts('Your user record does not have a valid email address'));
         }
         if (!trim($fromContactName)) {
             $fromContactName = $fromContactEmail;
         }
         $this->assign('fromName', "\"{$fromContactName}\" <{$fromContactEmail}>");
         $this->assign('sentDate', $dao->sent_date);
         $this->assign('subject', $dao->subject);
         $this->assign('message', $dao->message);
         // get the display name and images for the contact
         list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($dao->contact_id);
         CRM_Utils_System::setTitle($contactImage . ' ' . $displayName);
         require_once 'CRM/Core/Menu.php';
         // also add the cid params to the Menu array
         CRM_Core_Menu::addParam('cid', $cid);
     }
     parent::run();
 }
예제 #3
0
/**
 * This function adds the activity history variable in $values to the
 * parameter list $params.  For most cases, $values should have length 1.
 *
 * @param array  $values    The variable(s) to be added
 * @param array  $params    The structured parameter list
 * 
 * @return bool|CRM_Utils_Error
 * @access public
 */
function _crm_add_formatted_history_param(&$values, &$params)
{
    /* Cache the various object fields */
    static $fields = null;
    if ($fields == null) {
        $fields = array();
    }
    //print_r($values);
    //print_r($params);
    if (isset($values['activity_type'])) {
        $params['activity_type'] = $values['activity_type'];
        return true;
    }
    if (isset($values['activity_date'])) {
        $params['activity_date'] = $values['activity_date'];
        return true;
    }
    if (isset($values['activity_id'])) {
        $params['activity_id'] = $values['activity_id'];
        return true;
    }
    /* Check for custom field values */
    if ($fields['custom'] == null) {
        $fields['custom'] =& CRM_Core_BAO_CustomField::getFields('Contribution');
    }
    foreach ($values as $key => $value) {
        if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
            /* check if it's a valid custom field id */
            if (!array_key_exists($customFieldID, $fields['custom'])) {
                return _crm_error('Invalid custom field ID');
            }
            if (!isset($params['custom'])) {
                $params['custom'] = array();
            }
            // fixed for Import
            $newMulValues = array();
            if ($fields['custom'][$customFieldID][3] == 'CheckBox' || $fields['custom'][$customFieldID][3] == 'Multi-Select') {
                $value = str_replace("|", ",", $value);
                $mulValues = explode(',', $value);
                $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                foreach ($mulValues as $v1) {
                    foreach ($custuomOption as $v2) {
                        if (strtolower($v2['label']) == strtolower(trim($v1))) {
                            $newMulValues[] = $v2['value'];
                        }
                    }
                }
                $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $newMulValues);
            } else {
                if ($fields['custom'][$customFieldID][3] == 'Select' || $fields['custom'][$customFieldID][3] == 'Radio') {
                    $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
                    foreach ($custuomOption as $v2) {
                        if (strtolower($v2['label']) == strtolower(trim($value))) {
                            $value = $v2['value'];
                            break;
                        }
                    }
                }
            }
            $customBlock = count($params['custom']) + 1;
            $params['custom'][$customBlock] = array('custom_field_id' => $customFieldID, 'value' => $value, 'type' => $fields['custom'][$customFieldID][2], 'name' => $fields['custom'][$customFieldID][0]);
        }
    }
    /* Finally, check for contribution fields */
    if (!isset($fields['History'])) {
        $fields['History'] =& CRM_Core_DAO_ActivityHistory::fields();
    }
    _crm_store_values($fields['History'], $values, $params);
}
 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_HISTORY_IMPORT_PARSER_VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     //for date-Formats
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     foreach ($params as $key => $val) {
         if ($key == 'activity_date') {
             if ($val) {
                 if ($dateType == 1) {
                     $params[$key] = CRM_Utils_Date::customFormat($val, '%Y%m%d');
                 } else {
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                 }
             }
         }
     }
     //date-Format part ends
     $formatted = array();
     if ($GLOBALS['_CRM_HISTORY_IMPORT_PARSER_ACTIVITYHISTORY']['indieFields'] == null) {
         require_once 'CRM/Core/DAO/ActivityHistory.php';
         $tempIndieFields =& CRM_Core_DAO_ActivityHistory::import();
         $GLOBALS['_CRM_HISTORY_IMPORT_PARSER_ACTIVITYHISTORY']['indieFields'] = $tempIndieFields;
     }
     foreach ($params as $key => $field) {
         if ($field == null || $field === '') {
             continue;
         }
         $value = array($key => $field);
         _crm_add_formatted_history_param($value, $formatted);
     }
     if ($this->_contactIdIndex < 0) {
         if ($GLOBALS['_CRM_HISTORY_IMPORT_PARSER_ACTIVITYHISTORY']['cIndieFields'] == null) {
             require_once 'CRM/Contact/BAO/Contact.php';
             $cTempIndieFields = CRM_Contact_BAO_Contact::importableFields('Individual', null);
             $GLOBALS['_CRM_HISTORY_IMPORT_PARSER_ACTIVITYHISTORY']['cIndieFields'] = $cTempIndieFields;
         }
         foreach ($params as $key => $field) {
             if ($field == null || $field === '') {
                 continue;
             }
             if (is_array($field)) {
                 foreach ($field as $value) {
                     $break = false;
                     if (is_array($value)) {
                         foreach ($value as $name => $testForEmpty) {
                             if ($name !== 'phone_type' && ($testForEmpty === '' || $testForEmpty == null)) {
                                 $break = true;
                                 break;
                             }
                         }
                     } else {
                         $break = true;
                     }
                     if (!$break) {
                         _crm_add_formatted_param($value, $contactFormatted);
                     }
                 }
                 continue;
             }
             $value = array($key => $field);
             if (array_key_exists($key, $GLOBALS['_CRM_HISTORY_IMPORT_PARSER_ACTIVITYHISTORY']['cIndieFields'])) {
                 if (substr($key, 0, 6) != 'custom') {
                     $value['contact_type'] = 'Individual';
                 }
             }
             _crm_add_formatted_param($value, $contactFormatted);
         }
         $contactFormatted['contact_type'] = 'Individual';
         $error = _crm_duplicate_formatted_contact($contactFormatted);
         if (CRM_History_Import_Parser_ActivityHistory::isDuplicate($error)) {
             $matchedIDs = explode(',', $error->_errors[0]['params'][0]);
             if (count($matchedIDs) > 1) {
                 array_unshift($values, "Multiple matching contact records detected for this row. The activity history was not imported");
                 return CRM_HISTORY_IMPORT_PARSER_ERROR;
             } else {
                 $cid = $matchedIDs[0];
                 $formatted['entity_id'] = $cid;
                 $formatted['entity_table'] = 'civicrm_contact';
                 $newHistory = crm_create_activity_history($formatted);
                 if (is_a($newHistory, CRM_Core_Error)) {
                     array_unshift($values, $newHistory->_errors[0]['message']);
                     return CRM_HISTORY_IMPORT_PARSER_ERROR;
                 }
                 $this->_newHistory[] = $newHistory->id;
                 return CRM_HISTORY_IMPORT_PARSER_VALID;
             }
         } else {
             require_once 'CRM/Core/DAO/DupeMatch.php';
             $dao =& new CRM_Core_DAO_DupeMatch();
             $dao->find(true);
             $fieldsArray = explode('AND', $dao->rule);
             foreach ($fieldsArray as $value) {
                 if (array_key_exists(trim($value), $params)) {
                     $paramValue = $params[trim($value)];
                     if (is_array($paramValue)) {
                         $disp .= $params[trim($value)][0][trim($value)] . " ";
                     } else {
                         $disp .= $params[trim($value)] . " ";
                     }
                 }
             }
             array_unshift($values, "No matching Contact found for (" . $disp . ")");
             return CRM_HISTORY_IMPORT_PARSER_ERROR;
         }
     } else {
         $formatted['entity_table'] = 'civicrm_contact';
         $newHistory = crm_create_activity_history($formatted);
         if (is_a($newHistory, CRM_Core_Error)) {
             array_unshift($values, $newHistory->_errors[0]['message']);
             return CRM_HISTORY_IMPORT_PARSER_ERROR;
         }
         $this->_newHistory[] = $newHistory->id;
         return CRM_HISTORY_IMPORT_PARSER_VALID;
     }
 }
예제 #5
0
 /**
  * combine all the importable fields from the lower levels object
  *
  * The ordering is important, since currently we do not have a weight
  * scheme. Adding weight is super important and should be done in the
  * next week or so, before this can be called complete.
  *
  * @param NULL
  * 
  * @return array    array of importable Fields
  * @access public
  */
 function &importableFields()
 {
     if (!$GLOBALS['_CRM_CORE_BAO_HISTORY']['_importableFields']) {
         if (!$GLOBALS['_CRM_CORE_BAO_HISTORY']['_importableFields']) {
             $GLOBALS['_CRM_CORE_BAO_HISTORY']['_importableFields'] = array();
         }
         if (!$status) {
             $fields = array('' => array('title' => ts('- do not import -')));
         } else {
             $fields = array('' => array('title' => ts('- Contribution Fields -')));
         }
         require_once 'CRM/Core/DAO/ActivityHistory.php';
         $tmpFields = CRM_Core_DAO_ActivityHistory::import();
         $contactFields = CRM_Contact_BAO_Contact::importableFields('Individual', null);
         require_once 'CRM/Core/DAO/DupeMatch.php';
         $dao =& new CRM_Core_DAO_DupeMatch();
         $dao->find(true);
         $fieldsArray = explode('AND', $dao->rule);
         $tmpConatctField = array();
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 $tmpConatctField[trim($value)] = $contactFields[trim($value)];
                 $tmpConatctField[trim($value)]['title'] = $tmpConatctField[trim($value)]['title'] . " (match to contact)";
             }
         }
         $fields = array_merge($fields, $tmpConatctField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Activities'));
         $GLOBALS['_CRM_CORE_BAO_HISTORY']['_importableFields'] = $fields;
     }
     return $GLOBALS['_CRM_CORE_BAO_HISTORY']['_importableFields'];
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!$GLOBALS['_CRM_CORE_DAO_ACTIVITYHISTORY']['_export']) {
         $GLOBALS['_CRM_CORE_DAO_ACTIVITYHISTORY']['_export'] = array();
         $fields =& CRM_Core_DAO_ActivityHistory::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     $GLOBALS['_CRM_CORE_DAO_ACTIVITYHISTORY']['_export']['activity_history'] =& $fields[$name];
                 } else {
                     $GLOBALS['_CRM_CORE_DAO_ACTIVITYHISTORY']['_export'][$name] =& $fields[$name];
                 }
             }
         }
     }
     return $GLOBALS['_CRM_CORE_DAO_ACTIVITYHISTORY']['_export'];
 }