Example #1
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe');
     $this->_duplicateButtonName = $this->getButtonName('next', 'duplicate');
     if ($this->_action == CRM_CORE_ACTION_ADD) {
         $this->_contactType = CRM_Utils_Request::retrieve('c_type', $this, true, null, 'REQUEST');
         $this->_gid = CRM_Utils_Request::retrieve('gid', $this, false, null, 'GET');
         $this->_tid = CRM_Utils_Request::retrieve('tid', $this, false, null, 'GET');
         $this->_contactId = null;
     } else {
         // this is update mode, first get the id from the session
         // else get it from the REQUEST
         $ids = $this->get('ids');
         $this->_contactId = CRM_Utils_Array::value('contact', $ids);
         if (!$this->_contactId) {
             $this->_contactId = CRM_Utils_Array::value('cid', $_REQUEST);
         }
         if ($this->_contactId) {
             $contact =& new CRM_Contact_DAO_Contact();
             $contact->id = $this->_contactId;
             if (!$contact->find(true)) {
                 CRM_Utils_System::statusBounce(ts('contact does not exist: %1', array(1 => $this->_contactId)));
             }
             $this->_contactType = $contact->contact_type;
             // check for permissions
             if (!CRM_Contact_BAO_Contact::permissionedContact($this->_contactId, CRM_CORE_PERMISSION_EDIT)) {
                 CRM_Utils_System::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
             }
             return;
         }
         CRM_Utils_System::statusBounce(ts('Could not get a contact_id and/or contact_type'));
     }
 }
Example #2
0
 /**
  * Heart of the viewing process. The runner gets all the meta data for
  * the contact and calls the appropriate type of page to view.
  *
  * @return void
  * @access public
  *
  */
 function preProcess()
 {
     $this->_id = CRM_Utils_Request::retrieve('id', $this);
     $this->assign('id', $this->_id);
     $this->_contactId = CRM_Utils_Request::retrieve('cid', $this, true);
     if (!$this->_contactId) {
         CRM_Utils_System::statusBounce(ts('We could not find a contact id.'));
     }
     $this->assign('contactId', $this->_contactId);
     $this->_action = CRM_Utils_Request::retrieve('action', $this, false, 'browse');
     $this->assign('action', $this->_action);
     // check for permissions
     $this->_permission = null;
     if (CRM_Contact_BAO_Contact::permissionedContact($this->_contactId, CRM_CORE_PERMISSION_EDIT)) {
         $this->assign('permission', 'edit');
         $this->_permission = CRM_CORE_PERMISSION_EDIT;
     } else {
         if (CRM_Contact_BAO_Contact::permissionedContact($this->_contactId, CRM_CORE_PERMISSION_VIEW)) {
             $this->assign('permission', 'view');
             $this->_permission = CRM_CORE_PERMISSION_VIEW;
         } else {
             CRM_Utils_System::statusBounce(ts('You do not have the necessary permission to view this contact.'));
         }
     }
     $this->getContactDetails();
     $contactImage = $this->get('contactImage');
     $displayName = $this->get('displayName');
     $this->assign('displayName', $displayName);
     CRM_Utils_System::setTitle($contactImage . ' ' . $displayName);
     CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId), $contactImage, $this->_contactId);
     // also add the cid params to the Menu array
     CRM_Utils_Menu::addParam('cid', $this->_contactId);
     $this->assign('viewForm', $form);
     $this->assign('showBlocks1', $showBlocks);
     $this->assign('hideBlocks1', $hideBlocks);
     $this->assign('groupTree', $_groupTree);
     //------------
     // create menus ..
     $startWeight = CRM_Utils_Menu::getMaxWeight('civicrm/contact/view');
     $startWeight++;
     CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($this->_contactId), 'civicrm/contact/view/cd', $startWeight);
     //display OtherActivity link
     $otherAct = CRM_Core_PseudoConstant::activityType(false);
     $activityNum = count($otherAct);
     $this->assign('showOtherActivityLink', $activityNum);
 }
Example #3
0
 /**
  * Delete a contact and all its associated records
  * 
  * @param  int  $id id of the contact to delete
  *
  * @return boolean true if contact deleted, false otherwise
  * @access public
  * @static
  */
 function deleteContact($id)
 {
     require_once 'CRM/Core/BAO/EmailHistory.php';
     require_once 'CRM/Core/BAO/Meeting.php';
     require_once 'CRM/Core/BAO/Phonecall.php';
     // make sure we have edit permission for this contact
     // before we delete
     if (!CRM_Contact_BAO_Contact::permissionedContact($id, CRM_CORE_PERMISSION_EDIT)) {
         return false;
     }
     require_once 'CRM/Utils/Hook.php';
     $contact =& new CRM_Contact_DAO_Contact();
     $contact->id = $id;
     if (!$contact->find(true)) {
         return false;
     }
     $contactType = $contact->contact_type;
     CRM_Utils_Hook::pre('delete', $contactType, $id);
     CRM_Core_DAO::transaction('BEGIN');
     // do a top down deletion
     CRM_Mailing_Event_BAO_Subscribe::deleteContact($id);
     CRM_Contact_BAO_GroupContact::deleteContact($id);
     CRM_Contact_BAO_SubscriptionHistory::deleteContact($id);
     CRM_Contact_BAO_Relationship::deleteContact($id);
     CRM_Contribute_BAO_Contribution::deleteContact($id);
     CRM_Core_BAO_Note::deleteContact($id);
     CRM_Core_DAO::deleteEntityContact('CRM_Core_DAO_CustomValue', $id);
     CRM_Core_DAO::deleteEntityContact('CRM_Core_DAO_ActivityHistory', $id);
     require_once 'CRM/Core/BAO/UFMatch.php';
     CRM_Core_BAO_UFMatch::deleteContact($id);
     // need to remove them from email, meeting and phonecall
     CRM_Core_BAO_EmailHistory::deleteContact($id);
     CRM_Core_BAO_Meeting::deleteContact($id);
     CRM_Core_BAO_Phonecall::deleteContact($id);
     // location shld be deleted after phonecall, since fields in phonecall are
     // fkeyed into location/phone.
     CRM_Core_BAO_Location::deleteContact($id);
     // fix household and org primary contact ids
     foreach ($GLOBALS['_CRM_CONTACT_BAO_CONTACT']['misc'] as $name) {
         require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $name) . ".php";
         eval('$object =& new CRM_Contact_DAO_' . $name . '( );');
         $object->primary_contact_id = $id;
         $object->find();
         while ($object->fetch()) {
             // we need to set this to null explicitly
             $object->primary_contact_id = 'null';
             $object->save();
         }
     }
     require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_BAO_" . $contactType) . ".php";
     eval('$object =& new CRM_Contact_BAO_' . $contactType . '( );');
     $object->contact_id = $contact->id;
     $object->delete();
     $contact->delete();
     //delete the contact id from recently view
     CRM_Utils_Recent::del($id);
     CRM_Core_DAO::transaction('COMMIT');
     CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact);
     return true;
 }