Example #1
0
 /**
  * This function is called when action is browse
  * 
  * return null
  * @access public
  */
 function browse()
 {
     require_once 'CRM/Core/DAO/Log.php';
     $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);
 }
 /**
  * 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&section=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);
 }
Example #3
0
 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;
 }
Example #4
0
 /**
  * @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;
 }
 /**
  * Delete a contact and all its associated records.
  *
  * @param int $id
  *   Id of the contact to delete.
  * @param bool $restore
  *   Whether to actually restore, not delete.
  * @param bool $skipUndelete
  *   Whether to force contact delete or not.
  *
  * @return bool
  *   Was contact deleted?
  */
 public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE)
 {
     if (!$id) {
         return FALSE;
     }
     // If trash is disabled in system settings then we always skip
     if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL, 1)) {
         $skipUndelete = TRUE;
     }
     // make sure we have edit permission for this contact
     // before we delete
     if ($skipUndelete && !CRM_Core_Permission::check('delete contacts') || $restore && !CRM_Core_Permission::check('access deleted contacts')) {
         return FALSE;
     }
     // CRM-12929
     // Restrict contact to be delete if contact has financial trxns
     $error = NULL;
     if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($id), $error)) {
         return FALSE;
     }
     // make sure this contact_id does not have any membership types
     $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id');
     if ($membershipTypeID) {
         return FALSE;
     }
     $contact = new CRM_Contact_DAO_Contact();
     $contact->id = $id;
     if (!$contact->find(TRUE)) {
         return FALSE;
     }
     $contactType = $contact->contact_type;
     // currently we only clear employer cache.
     // we are now deleting inherited membership if any.
     if ($contact->contact_type == 'Organization') {
         $action = $restore ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
         $relationshipDtls = CRM_Contact_BAO_Relationship::getRelationship($id);
         if (!empty($relationshipDtls)) {
             foreach ($relationshipDtls as $rId => $details) {
                 CRM_Contact_BAO_Relationship::disableEnableRelationship($rId, $action);
             }
         }
         CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id);
     }
     if ($restore) {
         return self::contactTrashRestore($contact, TRUE);
     }
     // start a new transaction
     $transaction = new CRM_Core_Transaction();
     if ($skipUndelete) {
         CRM_Utils_Hook::pre('delete', $contactType, $id, CRM_Core_DAO::$_nullArray);
         //delete billing address if exists.
         CRM_Contribute_BAO_Contribution::deleteAddress(NULL, $id);
         // delete the log entries since we dont have triggers enabled as yet
         $logDAO = new CRM_Core_DAO_Log();
         $logDAO->entity_table = 'civicrm_contact';
         $logDAO->entity_id = $id;
         $logDAO->delete();
         // delete contact participants CRM-12155
         CRM_Event_BAO_Participant::deleteContactParticipant($id);
         // delete contact contributions CRM-12155
         CRM_Contribute_BAO_Contribution::deleteContactContribution($id);
         // do activity cleanup, CRM-5604
         CRM_Activity_BAO_Activity::cleanupActivity($id);
         // delete all notes related to contact
         CRM_Core_BAO_Note::cleanContactNotes($id);
         // delete cases related to contact
         $contactCases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($id);
         if (!empty($contactCases)) {
             foreach ($contactCases as $caseId) {
                 //check if case is associate with other contact or not.
                 $caseContactId = CRM_Case_BAO_Case::getCaseClients($caseId);
                 if (count($caseContactId) <= 1) {
                     CRM_Case_BAO_Case::deleteCase($caseId);
                 }
             }
         }
         $contact->delete();
     } else {
         self::contactTrashRestore($contact);
     }
     //delete the contact id from recently view
     CRM_Utils_Recent::delContact($id);
     // Update the group contact cache
     if ($restore) {
         CRM_Contact_BAO_GroupContactCache::remove();
     } else {
         CRM_Contact_BAO_GroupContactCache::removeContact($id);
     }
     // delete any dupe cache entry
     CRM_Core_BAO_PrevNextCache::deleteItem($id);
     $transaction->commit();
     if ($skipUndelete) {
         CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact);
     }
     // also reset the DB_DO global array so we can reuse the memory
     // http://issues.civicrm.org/jira/browse/CRM-4387
     CRM_Core_DAO::freeResult();
     return TRUE;
 }
Example #6
0
 /**
  * @param bool $created
  */
 public function log($created = FALSE)
 {
     static $cid = NULL;
     if (!$this->getLog()) {
         return;
     }
     if (!$cid) {
         $session = CRM_Core_Session::singleton();
         $cid = $session->get('userID');
     }
     // return is we dont have handle to FK
     if (!$cid) {
         return;
     }
     $dao = new CRM_Core_DAO_Log();
     $dao->entity_table = $this->getTableName();
     $dao->entity_id = $this->id;
     $dao->modified_id = $cid;
     $dao->modified_date = date("YmdHis");
     $dao->insert();
 }
Example #7
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  * @static
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['log'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Example #8
0
 function log($created = false)
 {
     static $cid = null;
     if (!$this->getLog()) {
         return;
     }
     if (!$cid) {
         $session =& CRM_Core_Session::singleton();
         $cid = $session->get('userID');
     }
     // return is we dont have handle to FK
     if (!$cid) {
         return;
     }
     require_once 'CRM/Core/DAO/Log.php';
     $dao = new CRM_Core_DAO_Log();
     $dao->entity_table = $this->getTableName();
     $dao->entity_id = $this->id;
     $dao->modified_id = $cid;
     $dao->modified_date = date("YmdHis");
     $dao->insert();
 }
 /**
  * Delete a contact and all its associated records
  *
  * @param  int  $id id of the contact to delete
  * @param  bool $restore       whether to actually restore, not delete
  * @param  bool $skipUndelete  whether to force contact delete or not
  *
  * @return boolean true if contact deleted, false otherwise
  * @access public
  * @static
  */
 static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE)
 {
     if (!$id) {
         return FALSE;
     }
     // make sure we have edit permission for this contact
     // before we delete
     if ($skipUndelete && !CRM_Core_Permission::check('delete contacts') || $restore && !CRM_Core_Permission::check('access deleted contacts')) {
         return FALSE;
     }
     // make sure this contact_id does not have any membership types
     $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id');
     if ($membershipTypeID) {
         return FALSE;
     }
     $contact = new CRM_Contact_DAO_Contact();
     $contact->id = $id;
     if (!$contact->find(TRUE)) {
         return FALSE;
     }
     $contactType = $contact->contact_type;
     $action = $restore ? 'restore' : 'delete';
     CRM_Utils_Hook::pre($action, $contactType, $id, CRM_Core_DAO::$_nullArray);
     if ($restore) {
         self::contactTrashRestore($contact, TRUE);
         CRM_Utils_Hook::post($action, $contactType, $contact->id, $contact);
         return TRUE;
     }
     // currently we only clear employer cache.
     // we are not deleting inherited membership if any.
     if ($contact->contact_type == 'Organization') {
         CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id);
     }
     // start a new transaction
     $transaction = new CRM_Core_Transaction();
     $config = CRM_Core_Config::singleton();
     if ($skipUndelete or !$config->contactUndelete) {
         //delete billing address if exists.
         CRM_Contribute_BAO_Contribution::deleteAddress(NULL, $id);
         // delete the log entries since we dont have triggers enabled as yet
         $logDAO = new CRM_Core_DAO_Log();
         $logDAO->entity_table = 'civicrm_contact';
         $logDAO->entity_id = $id;
         $logDAO->delete();
         // do activity cleanup, CRM-5604
         CRM_Activity_BAO_Activity::cleanupActivity($id);
         // delete all notes related to contact
         CRM_Core_BAO_Note::cleanContactNotes($id);
         $contact->delete();
     } else {
         self::contactTrashRestore($contact);
     }
     //delete the contact id from recently view
     CRM_Utils_Recent::delContact($id);
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
     // delete any dupe cache entry
     CRM_Core_BAO_PrevNextCache::deleteItem($id);
     $transaction->commit();
     CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact);
     // also reset the DB_DO global array so we can reuse the memory
     // http://issues.civicrm.org/jira/browse/CRM-4387
     CRM_Core_DAO::freeResult();
     return TRUE;
 }