/** * @param $contactID * @param $tableName * @param $tableID * @param null $userID */ static function register($contactID, $tableName, $tableID, $userID = NULL) { if (!self::$_processed) { self::$_processed = array(); } if (!$userID) { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); } if (!$userID) { $api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST'); if ($api_key && strtolower($api_key) != 'null') { $userID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key'); } } if (!$userID) { $userID = $contactID; } if (!$userID) { return; } $log = new CRM_Core_DAO_Log(); $log->id = NULL; if (isset(self::$_processed[$contactID])) { if (isset(self::$_processed[$contactID][$userID])) { $log->id = self::$_processed[$contactID][$userID]; } self::$_processed[$contactID][$userID] = 1; } else { self::$_processed[$contactID] = array($userID => 1); } $logData = "{$tableName},{$tableID}"; if (!$log->id) { $log->entity_table = 'civicrm_contact'; $log->entity_id = $contactID; $log->modified_id = $userID; $log->modified_date = date("YmdHis"); $log->data = $logData; $log->save(); } else { $query = "\nUPDATE civicrm_log\n SET data = concat( data, ':{$logData}' )\n WHERE id = {$log->id}\n"; CRM_Core_DAO::executeQuery($query); } self::$_processed[$contactID][$userID] = $log->id; }
/** * This function is called when action is browse * * return null * @access public */ function browse() { $loggingReport = CRM_Core_BAO_Log::useLoggingReport(); $this->assign('useLogging', $loggingReport); if ($loggingReport) { $this->assign('instanceUrl', CRM_Utils_System::url("civicrm/report/instance/{$loggingReport}", "reset=1&force=1&snippet=4§ion=2&altered_contact_id_op=eq&altered_contact_id_value={$this->_contactId}&cid={$this->_contactId}", FALSE, NULL, FALSE)); return; } $log = new CRM_Core_DAO_Log(); $log->entity_table = 'civicrm_contact'; $log->entity_id = $this->_contactId; $log->orderBy('modified_date desc'); $log->find(); $logEntries = array(); while ($log->fetch()) { list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($log->modified_id); $logEntries[] = array('id' => $log->modified_id, 'name' => $displayName, 'image' => $contactImage, 'date' => $log->modified_date); } $this->assign('logCount', count($logEntries)); $this->assign_by_ref('log', $logEntries); }
static function register($contactID, $tableName, $tableID, $userID = null) { if (!self::$_processed) { self::$_processed = array(); } if (!$userID) { $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); } if (!$userID) { $userID = $contactID; } if (!$userID) { return; } $log =& new CRM_Core_DAO_Log(); $log->id = null; if (isset(self::$_processed[$contactID])) { if (isset(self::$_processed[$contactID][$userID])) { $log->id = self::$_processed[$contactID][$userID]; } self::$_processed[$contactID][$userID] = 1; } else { self::$_processed[$contactID] = array($userID => 1); } $logData = "{$tableName},{$tableID}"; if (!$log->id) { $log->entity_table = 'civicrm_contact'; $log->entity_id = $contactID; $log->modified_id = $userID; $log->modified_date = date("YmdHis"); $log->data = $logData; $log->save(); } else { $query = "\nUPDATE civicrm_log\n SET data = concat( data, ':{$logData}' )\n WHERE id = {$log->id}\n"; CRM_Core_DAO::executeQuery($query); } self::$_processed[$contactID][$userID] = $log->id; }
/** * Update the email value for the contact and user profile. * * @param int $contactId * Contact ID of the user. * @param string $emailAddress * Email to be modified for the user. */ public static function updateContactEmail($contactId, $emailAddress) { $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $emailAddress = $strtolower($emailAddress); $ufmatch = new CRM_Core_DAO_UFMatch(); $ufmatch->contact_id = $contactId; $ufmatch->domain_id = CRM_Core_Config::domainID(); if ($ufmatch->find(TRUE)) { // Save the email in UF Match table $ufmatch->uf_name = $emailAddress; CRM_Core_BAO_UFMatch::create((array) $ufmatch); //check if the primary email for the contact exists //$contactDetails[1] - email //$contactDetails[3] - email id $contactDetails = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactId); if (trim($contactDetails[1])) { $emailID = $contactDetails[3]; //update if record is found $query = "UPDATE civicrm_email\n SET email = %1\n WHERE id = %2"; $p = array(1 => array($emailAddress, 'String'), 2 => array($emailID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $p); } else { //else insert a new email record $email = new CRM_Core_DAO_Email(); $email->contact_id = $contactId; $email->is_primary = 1; $email->email = $emailAddress; $email->save(); $emailID = $email->id; } CRM_Core_BAO_Log::register($contactId, 'civicrm_email', $emailID); } }
/** * takes an associative array and creates a participant object * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Event_BAO_Participant object * @access public * @static */ static function &create(&$params) { require_once 'CRM/Utils/Date.php'; require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $status = null; if (CRM_Utils_Array::value('id', $params)) { $status = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $params['id'], 'status_id'); } $participant =& self::add($params); if (is_a($participant, 'CRM_Core_Error')) { $transaction->rollback(); return $participant; } if (!CRM_Utils_Array::value('id', $params) || $params['status_id'] != $status) { require_once 'CRM/Activity/BAO/Activity.php'; CRM_Activity_BAO_Activity::addActivity($participant); } //CRM-5403 //for update mode if (self::isPrimaryParticipant($participant->id) && $status) { self::updateParticipantStatus($participant->id, $status, $participant->status_id); } $session =& CRM_Core_Session::singleton(); $id = $session->get('userID'); if (!$id) { $id = $params['contact_id']; } // add custom field values if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) { require_once 'CRM/Core/BAO/CustomValueTable.php'; CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_participant', $participant->id); } if (CRM_Utils_Array::value('note', $params) || CRM_Utils_Array::value('participant_note', $params)) { if (CRM_Utils_Array::value('note', $params)) { $note = CRM_Utils_Array::value('note', $params); } else { $note = CRM_Utils_Array::value('participant_note', $params); } $noteDetails = CRM_Core_BAO_Note::getNote($participant->id, 'civicrm_participant'); $noteIDs = array(); if (!empty($noteDetails)) { $noteIDs['id'] = array_pop(array_flip($noteDetails)); } if ($note) { require_once 'CRM/Core/BAO/Note.php'; $noteParams = array('entity_table' => 'civicrm_participant', 'note' => $note, 'entity_id' => $participant->id, 'contact_id' => $id, 'modified_date' => date('Ymd')); CRM_Core_BAO_Note::add($noteParams, $noteIDs); } } // Log the information on successful add/edit of Participant data. require_once 'CRM/Core/BAO/Log.php'; $logParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $participant->id, 'data' => CRM_Event_PseudoConstant::participantStatus($participant->status_id), 'modified_id' => $id, 'modified_date' => date('Ymd')); CRM_Core_BAO_Log::add($logParams); $params['participant_id'] = $participant->id; $transaction->commit(); // do not add to recent items for import, CRM-4399 if (!CRM_Utils_Array::value('skipRecentView', $params)) { require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Event/PseudoConstant.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"); $recentOther = array(); if (CRM_Core_Permission::check('edit event participants')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"); } if (CRM_Core_Permission::check('delete in CiviEvent')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"); } $participantRoles = CRM_Event_PseudoConstant::participantRole(); if ($participant->role_id) { $role = explode(CRM_Core_DAO::VALUE_SEPARATOR, $participant->role_id); foreach ($role as $roleKey => $roleValue) { if (isset($roles)) { $roles .= ", " . $participantRoles[$roleValue]; } else { $roles = $participantRoles[$roleValue]; } } } $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'title'); $title = CRM_Contact_BAO_Contact::displayName($participant->contact_id) . ' (' . $roles . ' - ' . $eventTitle . ')'; // add the recently created Participant CRM_Utils_Recent::add($title, $url, $participant->id, 'Participant', $participant->contact_id, null, $recentOther); } return $participant; }
/** * Takes an associative array and creates a participant object. * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return CRM_Event_BAO_Participant */ public static function create(&$params) { $transaction = new CRM_Core_Transaction(); $status = NULL; if (!empty($params['id'])) { $status = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $params['id'], 'status_id'); } $participant = self::add($params); if (is_a($participant, 'CRM_Core_Error')) { $transaction->rollback(); return $participant; } if (!CRM_Utils_Array::value('id', $params) || isset($params['status_id']) && $params['status_id'] != $status) { CRM_Activity_BAO_Activity::addActivity($participant); } //CRM-5403 //for update mode if (self::isPrimaryParticipant($participant->id) && $status) { self::updateParticipantStatus($participant->id, $status, $participant->status_id); } $session = CRM_Core_Session::singleton(); $id = $session->get('userID'); if (!$id) { $id = CRM_Utils_Array::value('contact_id', $params); } // add custom field values if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_participant', $participant->id); } //process note, CRM-7634 $noteId = NULL; if (!empty($params['id'])) { $note = CRM_Core_BAO_Note::getNote($params['id'], 'civicrm_participant'); $noteId = key($note); } $noteValue = NULL; $hasNoteField = FALSE; foreach (array('note', 'participant_note') as $noteFld) { if (array_key_exists($noteFld, $params)) { $noteValue = $params[$noteFld]; $hasNoteField = TRUE; break; } } if ($noteId || $noteValue) { if ($noteValue) { $noteParams = array('entity_table' => 'civicrm_participant', 'note' => $noteValue, 'entity_id' => $participant->id, 'contact_id' => $id, 'modified_date' => date('Ymd')); $noteIDs = array(); if ($noteId) { $noteIDs['id'] = $noteId; } CRM_Core_BAO_Note::add($noteParams, $noteIDs); } elseif ($noteId && $hasNoteField) { CRM_Core_BAO_Note::del($noteId, FALSE); } } // Log the information on successful add/edit of Participant data. $logParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $participant->id, 'data' => CRM_Event_PseudoConstant::participantStatus($participant->status_id), 'modified_id' => $id, 'modified_date' => date('Ymd')); CRM_Core_BAO_Log::add($logParams); $params['participant_id'] = $participant->id; $transaction->commit(); // do not add to recent items for import, CRM-4399 if (empty($params['skipRecentView'])) { $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"); $recentOther = array(); if (CRM_Core_Permission::check('edit event participants')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"); } if (CRM_Core_Permission::check('delete in CiviEvent')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"); } $participantRoles = CRM_Event_PseudoConstant::participantRole(); if ($participant->role_id) { $role = explode(CRM_Core_DAO::VALUE_SEPARATOR, $participant->role_id); foreach ($role as &$roleValue) { if (isset($roleValue)) { $roleValue = $participantRoles[$roleValue]; } } $roles = implode(', ', $role); } $roleString = empty($roles) ? '' : $roles; $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'title'); $title = CRM_Contact_BAO_Contact::displayName($participant->contact_id) . ' (' . $roleString . ' - ' . $eventTitle . ')'; // add the recently created Participant CRM_Utils_Recent::add($title, $url, $participant->id, 'Participant', $participant->contact_id, NULL, $recentOther); } return $participant; }
/** * Common function for all inline contact edit forms * Prepares ajaxResponse * * @return void * @protected */ protected function response() { // Load changelog footer from template $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('contactId', $this->_contactId); $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'external_identifier')); $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact')); $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE); $smarty->assign('changeLog', $viewOptions['log']); $this->ajaxResponse = array_merge(array('changeLog' => array('count' => CRM_Contact_BAO_Contact::getCountComponent('log', $this->_contactId), 'markup' => $smarty->fetch('CRM/common/contactFooter.tpl'))), $this->ajaxResponse, CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId)); // Note: Post hooks will be called by CRM_Core_Form::mainProcess }
/** * process the form * * @return void * @access public */ public function postProcess() { $params = $this->exportValues(); // need to process / save address $params['contact_id'] = $this->_contactId; $params['updateBlankLocInfo'] = TRUE; // process shared contact address. CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']); if ($this->_parseStreetAddress) { CRM_Contact_Form_Contact::parseAddress($params); } if ($this->_addressId > 0) { $params['address'][$this->_locBlockNo]['id'] = $this->_addressId; } // save address changes $address = CRM_Core_BAO_Address::create($params, TRUE); // make entry in log table CRM_Core_BAO_Log::register($this->_contactId, 'civicrm_contact', $this->_contactId); $response = array('status' => 'save', 'addressId' => $address[0]->id); $this->postProcessHook(); echo json_encode($response); CRM_Utils_System::civiExit(); }
/** * takes an associative array and creates a contact object * * the function extract all the params it needs to initialize the create a * contact object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Contact_BAO_Contact object * @access public * @static */ static function add(&$params) { $contact =& new CRM_Contact_DAO_Contact(); if (empty($params)) { return; } //fixed contact source if (isset($params['contact_source'])) { $params['source'] = $params['contact_source']; } //fix for preferred communication method $prefComm = CRM_Utils_Array::value('preferred_communication_method', $params); if ($prefComm && is_array($prefComm)) { unset($params['preferred_communication_method']); $newPref = array(); foreach ($prefComm as $k => $v) { if ($v) { $newPref[$k] = $v; } } $prefComm = $newPref; if (is_array($prefComm) && !empty($prefComm)) { $prefComm = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($prefComm)) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; $contact->preferred_communication_method = $prefComm; } else { $contact->preferred_communication_method = ''; } } $allNull = $contact->copyValues($params); $contact->id = CRM_Utils_Array::value('contact_id', $params); if ($contact->contact_type == 'Individual') { $allNull = false; //format individual fields require_once "CRM/Contact/BAO/Individual.php"; CRM_Contact_BAO_Individual::format($params, $contact); } else { if ($contact->contact_type == 'Household') { if (isset($params['household_name'])) { $allNull = false; $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('household_name', $params, ''); } } else { if ($contact->contact_type == 'Organization') { if (isset($params['organization_name'])) { $allNull = false; $contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, ''); } } } } // privacy block $privacy = CRM_Utils_Array::value('privacy', $params); if ($privacy && is_array($privacy) && !empty($privacy)) { $allNull = false; foreach (self::$_commPrefs as $name) { $contact->{$name} = CRM_Utils_Array::value($name, $privacy, false); } } // since hash was required, make sure we have a 0 value for it, CRM-1063 // fixed in 1.5 by making hash optional // only do this in create mode, not update if ((!array_key_exists('hash', $contact) || !$contact->hash) && !$contact->id) { $allNull = false; $contact->hash = md5(uniqid(rand(), true)); } if (!$allNull) { $contact->save(); require_once 'CRM/Core/BAO/Log.php'; CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id); } if ($contact->contact_type == 'Individual' && array_key_exists('current_employer', $params)) { // create current employer if ($params['current_employer']) { require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $params['current_employer']); } else { //unset if employer id exits if ($employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact->id, 'employer_id')) { require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId); } } } //update cached employee name if ($contact->contact_type == 'Organization') { require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer($contact->id); } // process greetings CRM-4575, cache greetings self::processGreetings($contact); return $contact; }
/** * takes an associative array and creates a case object * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Case_BAO_Case object * @access public * @static */ static function &create(&$params) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $case = self::add($params); if (is_a($case, 'CRM_Core_Error')) { $transaction->rollback(); return $case; } $session =& CRM_Core_Session::singleton(); $id = $session->get('userID'); if (!$id) { $id = $params['contact_id']; } // Log the information on successful add/edit of Case require_once 'CRM/Core/BAO/Log.php'; $logParams = array('entity_table' => 'civicrm_case', 'entity_id' => $case->id, 'modified_id' => $id, 'modified_date' => date('Ymd')); CRM_Core_BAO_Log::add($logParams); $transaction->commit(); return $case; }
/** * Takes an associative array and creates a note object. * * the function extract all the params it needs to initialize the create a * note object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference) an assoc array of name/value pairs. * @param array $ids * (deprecated) associated array with note id - preferably set $params['id']. * * @return object * $note CRM_Core_BAO_Note object */ public static function add(&$params, $ids = array()) { $dataExists = self::dataExists($params); if (!$dataExists) { return CRM_Core_DAO::$_nullObject; } $note = new CRM_Core_BAO_Note(); if (!isset($params['modified_date'])) { $params['modified_date'] = date("Ymd"); } if (!isset($params['privacy'])) { $params['privacy'] = 0; } $note->copyValues($params); if (empty($params['contact_id'])) { if ($params['entity_table'] == 'civicrm_contact') { $note->contact_id = $params['entity_id']; } } $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); if ($id) { $note->id = $id; } $note->save(); // check and attach and files as needed CRM_Core_BAO_File::processAttachment($params, 'civicrm_note', $note->id); if ($note->entity_table == 'civicrm_contact') { CRM_Core_BAO_Log::register($note->entity_id, 'civicrm_note', $note->id); $displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id); $noteActions = FALSE; $session = CRM_Core_Session::singleton(); if ($session->get('userID')) { if ($session->get('userID') == $note->entity_id) { $noteActions = TRUE; } elseif (CRM_Contact_BAO_Contact_Permission::allow($note->entity_id, CRM_Core_Permission::EDIT)) { $noteActions = TRUE; } } $recentOther = array(); if ($noteActions) { $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=update&cid={$note->entity_id}&id={$note->id}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=delete&cid={$note->entity_id}&id={$note->id}&context=home")); } // add the recently created Note CRM_Utils_Recent::add($displayName . ' - ' . $note->subject, CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=view&cid={$note->entity_id}&id={$note->id}&context=home"), $note->id, 'Note', $note->entity_id, $displayName, $recentOther); } return $note; }
/** * Final response from successful form submit * * @param response: array - data to send to the client * * @return void * @protected */ protected function response($response = array()) { // Load changelog footer from template $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('contactId', $this->_contactId); $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'external_identifier')); $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact')); $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE); $smarty->assign('changeLog', $viewOptions['log']); $response = array_merge(array('status' => 'save', 'changeLog' => array('count' => CRM_Contact_BAO_Contact::getCountComponent('log', $this->_contactId), 'markup' => $smarty->fetch('CRM/common/contactFooter.tpl'))), $response, CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId)); $this->postProcessHook(); // CRM-11831 @see http://www.malsup.com/jquery/form/#file-upload $xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; if (!$xhr) { echo '<textarea>'; } echo json_encode($response); if (!$xhr) { echo '</textarea>'; } CRM_Utils_System::civiExit(); }
/** * process the form * * @return void * @access public */ public function postProcess() { $params = $this->exportValues(); // need to process / save emails $params['contact_id'] = $this->_contactId; $params['updateBlankLocInfo'] = TRUE; // save email changes CRM_Core_BAO_Block::create('email', $params); // make entry in log table CRM_Core_BAO_Log::register($this->_contactId, 'civicrm_contact', $this->_contactId); $response = array('status' => 'save'); $this->postProcessHook(); echo json_encode($response); CRM_Utils_System::civiExit(); }
/** * @param $newVersion * * @return bool */ public function logVersion($newVersion) { if ($newVersion) { $oldVersion = CRM_Core_BAO_Domain::version(); $session = CRM_Core_Session::singleton(); $logParams = array('entity_table' => 'civicrm_domain', 'entity_id' => 1, 'data' => "upgrade:{$oldVersion}->{$newVersion}", 'modified_date' => date('YmdHis')); CRM_Core_BAO_Log::add($logParams); return TRUE; } return FALSE; }
/** * takes an associative array and creates a note object * * the function extract all the params it needs to initialize the create a * note object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Core_BAO_Note object * @access public * @static */ static function &add(&$params, $ids) { $dataExists = self::dataExists($params); if (!$dataExists) { return CRM_Core_DAO::$_nullObject; } $note =& new CRM_Core_BAO_Note(); $params['modified_date'] = date("Ymd"); $note->copyValues($params); if (!$params['contact_id']) { if ($params['entity_table'] == 'civicrm_contact') { $note->contact_id = $params['entity_id']; } else { CRM_Core_Error::statusBounce(ts('We could not find your logged in user ID')); } } if (CRM_Utils_Array::value('id', $ids)) { $note->id = CRM_Utils_Array::value('id', $ids); } $note->save(); if ($note->entity_table == 'civicrm_contact') { require_once 'CRM/Core/BAO/Log.php'; CRM_Core_BAO_Log::register($note->entity_id, 'civicrm_note', $note->id); require_once 'CRM/Contact/BAO/Contact.php'; $displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id); // add the recently created Note require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::add($displayName . ' - ' . $note->subject, CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=view&cid={$note->entity_id}&id={$note->id}&context=home"), $note->id, 'Note', $note->entity_id, $displayName); } return $note; }
/** * takes an associative array and creates a note object * * the function extract all the params it needs to initialize the create a * note object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Core_BAO_Note object * @access public * @static */ static function &add(&$params, $ids) { $dataExists = self::dataExists($params); if (!$dataExists) { return CRM_Core_DAO::$_nullObject; } $note = new CRM_Core_BAO_Note(); if (!isset($params['modified_date'])) { $params['modified_date'] = date("Ymd"); } if (!isset($params['privacy'])) { $params['privacy'] = 0; } $note->copyValues($params); if (!$params['contact_id']) { if ($params['entity_table'] == 'civicrm_contact') { $note->contact_id = $params['entity_id']; } else { CRM_Core_Error::statusBounce(ts('We could not find your logged in user ID')); } } if (CRM_Utils_Array::value('id', $ids)) { $note->id = CRM_Utils_Array::value('id', $ids); } $note->save(); if ($note->entity_table == 'civicrm_contact') { require_once 'CRM/Core/BAO/Log.php'; CRM_Core_BAO_Log::register($note->entity_id, 'civicrm_note', $note->id); require_once 'CRM/Contact/BAO/Contact.php'; $displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id); $noteActions = false; $session = CRM_Core_Session::singleton(); if ($session->get('userID')) { require_once 'CRM/Contact/BAO/Contact/Permission.php'; if ($session->get('userID') == $note->entity_id) { $noteActions = true; } else { if (CRM_Contact_BAO_Contact_Permission::allow($note->entity_id, CRM_Core_Permission::EDIT)) { $noteActions = true; } } } $recentOther = array(); if ($noteActions) { $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=update&cid={$note->entity_id}&id={$note->id}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=delete&cid={$note->entity_id}&id={$note->id}&context=home")); } // add the recently created Note require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::add($displayName . ' - ' . $note->subject, CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=view&cid={$note->entity_id}&id={$note->id}&context=home"), $note->id, 'Note', $note->entity_id, $displayName, $recentOther); } return $note; }
/** * Process the user submitted custom data values. */ public function postProcess() { // Get the form values and groupTree //CRM-18183 $params = $this->controller->exportValues($this->_name); CRM_Core_BAO_CustomValueTable::postProcess($params, 'civicrm_contact', $this->_tableID, $this->_entityType); $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupID, 'table_name'); $cgcount = CRM_Core_BAO_CustomGroup::customGroupDataExistsForEntity($this->_tableID, $table, TRUE); $cgcount += 1; $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('upload', 'new')) { CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/cd/edit', "reset=1&type={$this->_contactType}&groupID={$this->_groupID}&entityID={$this->_tableID}&cgcount={$cgcount}&multiRecordDisplay=single&mode=add")); } // Add entry in the log table CRM_Core_BAO_Log::register($this->_tableID, 'civicrm_contact', $this->_tableID); if (CRM_Core_Resources::isAjaxMode()) { $this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_tableID); } // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); }
public function logActivityAction($activity, $logMessage = null) { $session =& CRM_Core_Session::singleton(); $id = $session->get('userID'); require_once 'CRM/Core/BAO/Log.php'; $logParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $activity->id, 'modified_id' => $id, 'modified_date' => date('YmdHis'), 'data' => $logMessage); CRM_Core_BAO_Log::add($logParams); return true; }
function logVersion($version = null) { if (!$version) { $version = CRM_Core_BAO_Domain::version(); } if ($version) { require_once 'CRM/Core/BAO/Log.php'; $session =& CRM_Core_Session::singleton(); $logParams = array('entity_table' => 'civicrm_domain', 'entity_id' => 1, 'data' => "version,{$version}", 'modified_date' => date('YmdHis')); CRM_Core_BAO_Log::add($logParams); return true; } return false; }
/** * function to create the event * * @param array $params reference array contains the values submitted by the form * * @return object * @access public * @static * */ public static function create(&$params) { $transaction = new CRM_Core_Transaction(); if (empty($params['is_template'])) { $params['is_template'] = 0; } // check if new event, if so set the created_id (if not set) // and always set created_date to now if (empty($params['id'])) { if (empty($params['created_id'])) { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } $params['created_date'] = date('YmdHis'); } $event = self::add($params); CRM_Price_BAO_PriceSet::setPriceSets($params, $event, 'event'); if (is_a($event, 'CRM_Core_Error')) { CRM_Core_DAO::transaction('ROLLBACK'); return $event; } $session = CRM_Core_Session::singleton(); $contactId = $session->get('userID'); if (!$contactId) { $contactId = CRM_Utils_Array::value('contact_id', $params); } // Log the information on successful add/edit of Event $logParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id, 'modified_id' => $contactId, 'modified_date' => date('Ymd')); CRM_Core_BAO_Log::add($logParams); if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_event', $event->id); } $transaction->commit(); return $event; }
/** * Given the component name and returns the count of participation of contact. * * @param string $component * Input component name. * @param int $contactId * Input contact id. * @param string $tableName * Optional tableName if component is custom group. * * @return int * total number in database */ public static function getCountComponent($component, $contactId, $tableName = NULL) { $object = NULL; switch ($component) { case 'tag': return CRM_Core_BAO_EntityTag::getContactTags($contactId, TRUE); case 'rel': $result = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::CURRENT, 0, 1); return $result; case 'group': return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, "Added", NULL, TRUE); case 'log': if (CRM_Core_BAO_Log::useLoggingReport()) { return FALSE; } return CRM_Core_BAO_Log::getContactLogCount($contactId); case 'note': return CRM_Core_BAO_Note::getContactNoteCount($contactId); case 'contribution': return CRM_Contribute_BAO_Contribution::contributionCount($contactId); case 'membership': return CRM_Member_BAO_Membership::getContactMembershipCount($contactId, TRUE); case 'participant': return CRM_Event_BAO_Participant::getContactParticipantCount($contactId); case 'pledge': return CRM_Pledge_BAO_Pledge::getContactPledgeCount($contactId); case 'case': return CRM_Case_BAO_Case::caseCount($contactId); case 'grant': return CRM_Grant_BAO_Grant::getContactGrantCount($contactId); case 'activity': $input = array('contact_id' => $contactId, 'admin' => FALSE, 'caseId' => NULL, 'context' => 'activity'); return CRM_Activity_BAO_Activity::getActivitiesCount($input); case 'mailing': $params = array('contact_id' => $contactId); return CRM_Mailing_BAO_Mailing::getContactMailingsCount($params); default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { if (!$tableName) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name'); } $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}"; return CRM_Core_DAO::singleValueQuery($queryString); } } }
/** * function to create the event * * @param array $params reference array contains the values submitted by the form * * @access public * @static * */ public static function create(&$params) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $event = self::add($params); if (is_a($event, 'CRM_Core_Error')) { CRM_Core_DAO::transaction('ROLLBACK'); return $event; } $session =& CRM_Core_Session::singleton(); $contactId = $session->get('userID'); if (!$contactId) { $contactId = CRM_Utils_Array::value('contact_id', $params); } // Log the information on successful add/edit of Event require_once 'CRM/Core/BAO/Log.php'; $logParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id, 'modified_id' => $contactId, 'modified_date' => date('Ymd')); CRM_Core_BAO_Log::add($logParams); if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) { require_once 'CRM/Core/BAO/CustomValueTable.php'; CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_event', $event->id); } $transaction->commit(); return $event; }
/** * Set a single value using the api. * * This function is called when no specific setvalue api exists. * Params must contain at least id=xx & {one of the fields from getfields}=value * * @param array $apiRequest * * @throws API_Exception * @return array */ function civicrm_api3_generic_setValue($apiRequest) { $entity = $apiRequest['entity']; $params = $apiRequest['params']; $id = $params['id']; if (!is_numeric($id)) { return civicrm_api3_create_error(ts('Please enter a number'), array('error_code' => 'NaN', 'field' => "id")); } $field = CRM_Utils_String::munge($params['field']); $value = $params['value']; $fields = civicrm_api($entity, 'getFields', array('version' => 3, 'action' => 'create', "sequential")); // getfields error, shouldn't happen. if ($fields['is_error']) { return $fields; } $fields = $fields['values']; $isCustom = strpos($field, 'custom_') === 0; // Trim off the id portion of a multivalued custom field name $fieldKey = $isCustom && substr_count($field, '_') > 1 ? rtrim(rtrim($field, '1234567890'), '_') : $field; if (!array_key_exists($fieldKey, $fields)) { return civicrm_api3_create_error("Param 'field' ({$field}) is invalid. must be an existing field", array("error_code" => "invalid_field", "fields" => array_keys($fields))); } $def = $fields[$fieldKey]; $title = CRM_Utils_Array::value('title', $def, ts('Field')); // Disallow empty values except for the number zero. // TODO: create a utility for this since it's needed in many places if (!empty($def['required']) || !empty($def['is_required'])) { if ((empty($value) || $value === 'null') && $value !== '0' && $value !== 0) { return civicrm_api3_create_error(ts('%1 is a required field.', array(1 => $title)), array("error_code" => "required", "field" => $field)); } } switch ($def['type']) { case CRM_Utils_Type::T_FLOAT: if (!is_numeric($value) && !empty($value) && $value !== 'null') { return civicrm_api3_create_error(ts('%1 must be a number.', array(1 => $title)), array('error_code' => 'NaN')); } break; case CRM_Utils_Type::T_INT: if (!CRM_Utils_Rule::integer($value) && !empty($value) && $value !== 'null') { return civicrm_api3_create_error(ts('%1 must be a number.', array(1 => $title)), array('error_code' => 'NaN')); } break; case CRM_Utils_Type::T_STRING: case CRM_Utils_Type::T_TEXT: if (!CRM_Utils_Rule::xssString($value)) { return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS')); } if (array_key_exists('maxlength', $def)) { $value = substr($value, 0, $def['maxlength']); } break; case CRM_Utils_Type::T_DATE: $value = CRM_Utils_Type::escape($value, "Date", FALSE); if (!$value) { return civicrm_api3_create_error("Param '{$field}' is not a date. format YYYYMMDD or YYYYMMDDHHMMSS"); } break; case CRM_Utils_Type::T_BOOLEAN: // Allow empty value for non-required fields if ($value === '' || $value === 'null') { $value = ''; } else { $value = (bool) $value; } break; default: return civicrm_api3_create_error("Param '{$field}' is of a type not managed yet (" . $def['type'] . "). Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED')); } $dao_name = _civicrm_api3_get_DAO($entity); $params = array('id' => $id, $field => $value); if ((!empty($def['pseudoconstant']) || !empty($def['option_group_id'])) && $value !== '' && $value !== 'null') { _civicrm_api3_api_match_pseudoconstant($params[$field], $entity, $field, $def); } CRM_Utils_Hook::pre('edit', $entity, $id, $params); // Custom fields if ($isCustom) { CRM_Utils_Array::crmReplaceKey($params, 'id', 'entityID'); // Treat 'null' as empty value. This is awful but the rest of the code supports it. if ($params[$field] === 'null') { $params[$field] = ''; } CRM_Core_BAO_CustomValueTable::setValues($params); CRM_Utils_Hook::post('edit', $entity, $id, CRM_Core_DAO::$_nullObject); } elseif (CRM_Core_DAO::setFieldValue($dao_name, $id, $field, $params[$field])) { $entityDAO = new $dao_name(); $entityDAO->copyValues($params); CRM_Utils_Hook::post('edit', $entity, $entityDAO->id, $entityDAO); } else { return civicrm_api3_create_error("error assigning {$field}={$value} for {$entity} (id={$id})"); } // Add changelog entry - TODO: Should we do this for other entities as well? if (strtolower($entity) === 'contact') { CRM_Core_BAO_Log::register($id, 'civicrm_contact', $id); } return civicrm_api3_create_success($params); }
/** * Given the component name and returns * the count of participation of contact * * @param string $component input component name * @param integer $contactId input contact id * @param string $tableName optional tableName if component is custom group * * @return total number of count of occurence in database * @access public * @static */ static function getCountComponent($component, $contactId, $tableName = null) { $object = null; switch ($component) { case 'tag': require_once 'CRM/Core/BAO/EntityTag.php'; return CRM_Core_BAO_EntityTag::getContactTags($contactId, true); case 'rel': require_once 'CRM/Contact/BAO/Relationship.php'; return count(CRM_Contact_BAO_Relationship::getRelationship($contactId)); case 'group': require_once 'CRM/Contact/BAO/GroupContact.php'; return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, null, null, true); case 'log': require_once 'CRM/Core/BAO/Log.php'; return CRM_Core_BAO_Log::getContactLogCount($contactId); case 'note': require_once 'CRM/Core/BAO/Note.php'; return CRM_Core_BAO_Note::getContactNoteCount($contactId); case 'contribution': require_once 'CRM/Contribute/BAO/Contribution.php'; return CRM_Contribute_BAO_Contribution::contributionCount($contactId); case 'membership': require_once 'CRM/Member/BAO/Membership.php'; return CRM_Member_BAO_Membership::getContactMembershipCount($contactId); case 'participant': require_once 'CRM/Event/BAO/Participant.php'; return CRM_Event_BAO_Participant::getContactParticipantCount($contactId); case 'pledge': require_once 'CRM/Pledge/BAO/Pledge.php'; return CRM_Pledge_BAO_Pledge::getContactPledgeCount($contactId); case 'case': require_once 'CRM/Case/BAO/Case.php'; return CRM_Case_BAO_Case::caseCount($contactId); case 'grant': require_once 'CRM/Grant/BAO/Grant.php'; return CRM_Grant_BAO_Grant::getContactGrantCount($contactId); case 'activity': require_once 'CRM/Activity/BAO/Activity.php'; return CRM_Activity_BAO_Activity::getActivitiesCount($contactId, false, null, null); default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { require_once 'CRM/Core/DAO/CustomGroup.php'; if (!$tableName) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name'); } $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}"; return CRM_Core_DAO::singleValueQuery($queryString); } } }
/** * Create the event. * * @param array $params * Reference array contains the values submitted by the form. * @param array $ids * Reference array contains the id. * * @return object */ public static function create(&$params, &$ids) { $transaction = new CRM_Core_Transaction(); $grant = self::add($params, $ids); if (is_a($grant, 'CRM_Core_Error')) { $transaction->rollback(); return $grant; } $session = CRM_Core_Session::singleton(); $id = $session->get('userID'); if (!$id) { $id = CRM_Utils_Array::value('contact_id', $params); } if (!empty($params['note']) || CRM_Utils_Array::value('id', CRM_Utils_Array::value('note', $ids))) { $noteParams = array('entity_table' => 'civicrm_grant', 'note' => $params['note'] = $params['note'] ? $params['note'] : "null", 'entity_id' => $grant->id, 'contact_id' => $id, 'modified_date' => date('Ymd')); CRM_Core_BAO_Note::add($noteParams, (array) CRM_Utils_Array::value('note', $ids)); } // Log the information on successful add/edit of Grant $logParams = array('entity_table' => 'civicrm_grant', 'entity_id' => $grant->id, 'modified_id' => $id, 'modified_date' => date('Ymd')); CRM_Core_BAO_Log::add($logParams); // add custom field values if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_grant', $grant->id); } // check and attach and files as needed CRM_Core_BAO_File::processAttachment($params, 'civicrm_grant', $grant->id); $transaction->commit(); return $grant; }
/** * View summary details of a contact. */ public function view() { // Add js for tabs, in-place editing, and jstree for tags CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header')->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header')->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')->addSetting(array('summaryPrint' => array('mode' => $this->_print), 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary')))); $this->assign('summaryPrint', $this->_print); $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); $session->pushUserContext($url); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); // Let summary page know if outbound mail is disabled so email links can be built conditionally $mailingBackend = Civi::settings()->get('mailing_backend'); $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']); $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type', 'daoName' => 'CRM_Core_DAO_Phone', 'fieldName' => 'phone_type_id'), 'im' => array('type' => 'IMProvider', 'id' => 'provider', 'daoName' => 'CRM_Core_DAO_IM', 'fieldName' => 'provider_id'), 'website' => array('type' => 'websiteType', 'id' => 'website_type', 'daoName' => 'CRM_Core_DAO_Website', 'fieldName' => 'website_type_id'), 'address' => array('skip' => TRUE, 'customData' => 1), 'email' => array('skip' => TRUE), 'openid' => array('skip' => TRUE)); foreach ($communicationType as $key => $value) { if (!empty($defaults[$key])) { foreach ($defaults[$key] as &$val) { CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE); if (empty($value['skip'])) { $daoName = $value['daoName']; $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE); } } if (isset($value['customData'])) { foreach ($defaults[$key] as $blockId => $blockVal) { $idValue = $blockVal['id']; if ($key == 'address') { if (!empty($blockVal['master_id'])) { $idValue = $blockVal['master_id']; } } $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $idValue); // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_"); } // reset template variable since that won't be of any use, and could be misleading $this->assign("dnc_viewCustomData", NULL); } } } if (!empty($defaults['gender_id'])) { $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']); } $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'); if (!empty($communicationStyle)) { if (!empty($defaults['communication_style_id'])) { $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)]; } else { // Make sure the field is displayed as long as it is active, even if it is unset for this contact. $defaults['communication_style_display'] = ''; } } // to make contact type label available in the template - $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type']; $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', '); // get contact tags $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); if (!empty($contactTags)) { $defaults['contactTag'] = implode(', ', $contactTags); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); //Show blocks only if they are visible in edit form $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options'); foreach ($this->_editOptions as $blockName => $value) { $varName = '_show' . $blockName; $this->{$varName} = $value; $this->assign(substr($varName, 1), $this->{$varName}); } // get contact name of shared contact names $sharedAddresses = array(); $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); foreach ($defaults['address'] as $key => $addressValue) { if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } } $this->assign('sharedAddresses', $sharedAddresses); //get the current employer name if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { if ($contact->employer_id && $contact->organization_name) { $defaults['current_employer'] = $contact->organization_name; $defaults['current_employer_id'] = $contact->employer_id; } //for birthdate format with respect to birth format set $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); } $defaults['external_identifier'] = $contact->external_identifier; $this->assign($defaults); // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query // also assign the last modifed details $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); $this->assign_by_ref('lastModified', $lastModified); $allTabs = array(); $weight = 10; $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE); // show the tabs only if user has generic access to CiviCRM $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM'); $changeLog = $this->_viewOptions['log']; $this->assign_by_ref('changeLog', $changeLog); $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { if (!empty($this->_viewOptions[$name]) && CRM_Core_Permission::access($component->name)) { $elem = $component->registerTab(); // FIXME: not very elegant, probably needs better approach // allow explicit id, if not defined, use keyword instead if (array_key_exists('id', $elem)) { $i = $elem['id']; } else { $i = $component->getKeyword(); } $u = $elem['url']; //appending isTest to url for test soft credit CRM-3891. //FIXME: hack ajax url. $q = "reset=1&force=1&cid={$this->_contactId}"; if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { $q .= "&isTest=1"; } $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId), 'class' => 'livePage'); // make sure to get maximum weight, rest of tabs go after // FIXME: not very elegant again if ($weight < $elem['weight']) { $weight = $elem['weight']; } } } $rest = array('activity' => array('title' => ts('Activities'), 'class' => 'livePage'), 'rel' => array('title' => ts('Relationships'), 'class' => 'livePage'), 'group' => array('title' => ts('Groups'), 'class' => 'ajaxForm'), 'note' => array('title' => ts('Notes'), 'class' => 'livePage'), 'tag' => array('title' => ts('Tags')), 'log' => array('title' => ts('Change Log'))); foreach ($rest as $k => $v) { if ($accessCiviCRM && !empty($this->_viewOptions[$k])) { $allTabs[] = $v + array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&cid={$this->_contactId}"), 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId)); $weight += 10; } } // now add all the custom tabs $entityType = $this->get('contactType'); $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId); foreach ($activeGroups as $group) { $id = "custom_{$group['id']}"; $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']), 'hideCount' => !$group['is_multiple'], 'class' => 'livePage'); $weight += 10; } $context = array('contact_id' => $this->_contactId); // see if any other modules want to add any tabs CRM_Utils_Hook::tabs($allTabs, $this->_contactId); CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context); $allTabs[] = array('id' => 'summary', 'url' => '#contact-summary', 'title' => ts('Summary'), 'weight' => 0); // now sort the tabs based on weight usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('allTabs', $allTabs); // hook for contact summary // ignored but needed to prevent warnings $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); if ($content) { $this->assign_by_ref('hookContent', $content); $this->assign('hookContentPlacement', $contentPlacement); } }
/** * Create an activity. * * @todo elaborate on what this does. * * @param CRM_Core_DAO_Activity $activity * @param string $logMessage * * @return bool */ public static function logActivityAction($activity, $logMessage = NULL) { $session = CRM_Core_Session::singleton(); $id = $session->get('userID'); if (!$id) { $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $id = self::getActivityContact($activity->id, $sourceID); } $logParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $activity->id, 'modified_id' => $id, 'modified_date' => date('YmdHis'), 'data' => $logMessage); CRM_Core_BAO_Log::add($logParams); return TRUE; }
/** * View summary details of a contact * * @return void * @access public */ function view() { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); $session->pushUserContext($url); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = true; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true); $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'website' => array('type' => 'websiteType', 'id' => 'website_type'), 'address' => array('skip' => true, 'customData' => 1), 'email' => array('skip' => true), 'openid' => array('skip' => true)); foreach ($communicationType as $key => $value) { if (CRM_Utils_Array::value($key, $defaults)) { foreach ($defaults[$key] as &$val) { CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false); if (!CRM_Utils_Array::value('skip', $value)) { eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false); } } if (isset($value['customData'])) { foreach ($defaults[$key] as $blockId => $blockVal) { $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $blockVal['id']); // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, false, null, "dnc_"); } // reset template variable since that won't be of any use, and could be misleading $this->assign("dnc_viewCustomData", null); } } } if (CRM_Utils_Array::value('gender_id', $defaults)) { $gender = CRM_Core_PseudoConstant::gender(); $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)]; } // to make contact type label available in the template - $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type']; $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(true, $contactType); // get contact tags require_once 'CRM/Core/BAO/EntityTag.php'; $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); if (!empty($contactTags)) { $defaults['contactTag'] = implode(', ', $contactTags); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); //Show blocks only if they are visible in edit form require_once 'CRM/Core/BAO/Preferences.php'; $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options'); $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes'); foreach ($configItems as $c => $t) { $varName = '_show' . $c; $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions); $this->assign(substr($varName, 1), $this->{$varName}); } // get contact name of shared contact names $sharedAddresses = array(); $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); foreach ($defaults['address'] as $key => $addressValue) { if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } } $this->assign('sharedAddresses', $sharedAddresses); //get the current employer name if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { if ($contact->employer_id && $contact->organization_name) { $defaults['current_employer'] = $contact->organization_name; $defaults['current_employer_id'] = $contact->employer_id; } //for birthdate format with respect to birth format set $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); } $this->assign($defaults); // also assign the last modifed details require_once 'CRM/Core/BAO/Log.php'; $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); $this->assign_by_ref('lastModified', $lastModified); $allTabs = array(); $weight = 10; $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true); $changeLog = $this->_viewOptions['log']; $this->assign_by_ref('changeLog', $changeLog); require_once 'CRM/Core/Component.php'; $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) { $elem = $component->registerTab(); // FIXME: not very elegant, probably needs better approach // allow explicit id, if not defined, use keyword instead if (array_key_exists('id', $elem)) { $i = $elem['id']; } else { $i = $component->getKeyword(); } $u = $elem['url']; //appending isTest to url for test soft credit CRM-3891. //FIXME: hack ajax url. $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}"; if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { $q = $q . "&isTest=1"; } $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId)); // make sure to get maximum weight, rest of tabs go after // FIXME: not very elegant again if ($weight < $elem['weight']) { $weight = $elem['weight']; } } } $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log')); $config = CRM_Core_Config::singleton(); if (isset($config->sunlight) && $config->sunlight) { $title = ts('Elected Officials'); $rest['sunlight'] = $title; $this->_viewOptions[$title] = true; } foreach ($rest as $k => $v) { if (CRM_Utils_Array::value($k, $this->_viewOptions)) { $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId)); $weight += 10; } } // now add all the custom tabs $entityType = $this->get('contactType'); $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId); foreach ($activeGroups as $group) { $id = "custom_{$group['id']}"; $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name'])); $weight += 10; } // see if any other modules want to add any tabs require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::tabs($allTabs, $this->_contactId); // now sort the tabs based on weight require_once 'CRM/Utils/Sort.php'; usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('allTabs', $allTabs); $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary'); $this->assign('selectedChild', $selectedChild); // hook for contact summary require_once 'CRM/Utils/Hook.php'; $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; // ignored but needed to prevent warnings CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); if ($content) { $this->assign_by_ref('hookContent', $content); $this->assign('hookContentPlacement', $contentPlacement); } }
/** * Render change log footer markup for a contact and supply count. * * Needed for refreshing the contact summary screen * * @param int $cid * @param bool $includeCount * @return array */ public static function renderFooter($cid, $includeCount = TRUE) { // Load change log footer from template. $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('contactId', $cid); $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier')); $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($cid, 'civicrm_contact')); $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE); $smarty->assign('changeLog', $viewOptions['log']); $ret = array('markup' => $smarty->fetch('CRM/common/contactFooter.tpl')); if ($includeCount) { $ret['count'] = CRM_Contact_BAO_Contact::getCountComponent('log', $cid); } return array('changeLog' => $ret); }
/** * View summary details of a contact * * @return void * @access public */ function view() { $session =& CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); $session->pushUserContext($url); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true); $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'address' => array('skip' => true), 'email' => array('skip' => true), 'openid' => array('skip' => true)); foreach ($communicationType as $key => $value) { if (CRM_Utils_Array::value($key, $defaults)) { foreach ($defaults[$key] as &$val) { CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false); if (!CRM_Utils_Array::value('skip', $value)) { eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false); } } } } if (CRM_Utils_Array::value('gender_id', $defaults)) { $gender = CRM_Core_PseudoConstant::gender(); $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)]; } if (CRM_Utils_Array::value('contact_sub_type', $defaults)) { $defaults['contact_sub_type'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $defaults['contact_sub_type'], 'label', 'name'); } // get the list of all the categories $tag =& CRM_Core_PseudoConstant::tag(); // get categories for the contact id require_once 'CRM/Core/BAO/EntityTag.php'; $entityTag =& CRM_Core_BAO_EntityTag::getTag($this->_contactId); if ($entityTag) { $categories = array(); foreach ($entityTag as $key) { $categories[] = $tag[$key]; } $defaults['contactTag'] = implode(', ', $categories); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); //Show blocks only if they are visible in edit form require_once 'CRM/Core/BAO/Preferences.php'; $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options'); $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes'); foreach ($configItems as $c => $t) { $varName = '_show' . $c; $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions); $this->assign(substr($varName, 1), $this->{$varName}); } //get the householdname if (isset($defaults['mail_to_household_id'])) { $HouseholdName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $defaults['mail_to_household_id'], 'display_name', 'id'); $this->assign('HouseholdName', $HouseholdName); } //get the current employer name if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { require_once 'CRM/Contact/BAO/Relationship.php'; $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId)); $defaults['current_employer'] = $currentEmployer[$this->_contactId]['org_name']; $defaults['current_employer_id'] = $currentEmployer[$this->_contactId]['org_id']; //for birthdate format with respect to birth format set $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); } $this->assign($defaults); // also assign the last modifed details require_once 'CRM/Core/BAO/Log.php'; $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); $this->assign_by_ref('lastModified', $lastModified); $allTabs = array(); $weight = 10; $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true); $changeLog = $this->_viewOptions['log']; $this->assign_by_ref('changeLog', $changeLog); require_once 'CRM/Core/Component.php'; $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) { $elem = $component->registerTab(); // FIXME: not very elegant, probably needs better approach // allow explicit id, if not defined, use keyword instead if (array_key_exists('id', $elem)) { $i = $elem['id']; } else { $i = $component->getKeyword(); } $u = $elem['url']; //appending isTest to url for test soft credit CRM-3891. //FIXME: hack ajax url. $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}"; if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { $q = $q . "&isTest=1"; } $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId)); // make sure to get maximum weight, rest of tabs go after // FIXME: not very elegant again if ($weight < $elem['weight']) { $weight = $elem['weight']; } } } $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log')); $config =& CRM_Core_Config::singleton(); if (isset($config->sunlight) && $config->sunlight) { $title = ts('Elected Officials'); $rest['sunlight'] = $title; $this->_viewOptions[$title] = true; } foreach ($rest as $k => $v) { if (CRM_Utils_Array::value($k, $this->_viewOptions)) { $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId)); $weight += 10; } } // now add all the custom tabs $activeGroups =& CRM_Core_BAO_CustomGroup::getActiveGroups(CRM_Contact_BAO_Contact::getContactType($this->_contactId), 'civicrm/contact/view/cd', $this->_contactId); foreach ($activeGroups as $group) { $id = "custom_{$group['id']}"; $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId)); $weight += 10; } // see if any other modules want to add any tabs require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::tabs($allTabs, $this->_contactId); if ($config->civiHRD) { $hrdOrder = array('rel' => 1, 'case' => 2, 'activity' => 3, 'participant' => 4, 'grant' => 5, 'contribute' => 6, 'group' => 7, 'note' => 8, 'tag' => 9, 'log' => 10); foreach ($allTabs as $i => $tab) { if (array_key_exists($tab['id'], $hrdOrder)) { $allTabs[$i]['weight'] = $hrdOrder[$tab['id']]; } } } // now sort the tabs based on weight require_once 'CRM/Utils/Sort.php'; usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('allTabs', $allTabs); $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary'); $this->assign('selectedChild', $selectedChild); // hook for contact summary require_once 'CRM/Utils/Hook.php'; $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; // ignored but needed to prevent warnings CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); if ($content) { $this->assign_by_ref('hookContent', $content); $this->assign('hookContentPlacement', $contentPlacement); } }