/**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
     $this->_searchKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     // sort out whether it’s a delete-to-trash, delete-into-oblivion or restore (and let the template know)
     $values = $this->controller->exportValues();
     $this->_skipUndelete = (CRM_Core_Permission::check('access deleted contacts') and (CRM_Utils_Request::retrieve('skip_undelete', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::DELETE_PERMANENTLY));
     $this->_restore = (CRM_Utils_Request::retrieve('restore', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::RESTORE);
     if ($this->_restore && !CRM_Core_Permission::check('access deleted contacts')) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this contact.'));
     } elseif (!CRM_Core_Permission::check('delete contacts')) {
         CRM_Core_Error::fatal(ts('You do not have permission to delete this contact.'));
     }
     $this->assign('trash', CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL) and !$this->_skipUndelete);
     $this->assign('restore', $this->_restore);
     if ($this->_restore) {
         CRM_Utils_System::setTitle(ts('Restore Contact'));
     }
     if ($cid) {
         if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT)) {
             CRM_Core_Error::fatal(ts('You do not have permission to delete this contact. Note: you can delete contacts if you can edit them.'));
         } elseif (CRM_Contact_BAO_Contact::checkDomainContact($cid)) {
             CRM_Core_Error::fatal(ts('This contact is a special one for the contact information associated with the CiviCRM installation for this domain. No one is allowed to delete it because the information is used for special system purposes.'));
         }
         $this->_contactIds = array($cid);
         $this->_single = TRUE;
         $this->assign('totalSelectedContacts', 1);
     } else {
         parent::preProcess();
     }
     $this->_sharedAddressMessage = $this->get('sharedAddressMessage');
     if (!$this->_restore && !$this->_sharedAddressMessage) {
         // we check for each contact for shared contact address
         $sharedContactList = array();
         $sharedAddressCount = 0;
         foreach ($this->_contactIds as $contactId) {
             // check if a contact that is being deleted has any shared addresses
             $sharedAddressMessage = CRM_Core_BAO_Address::setSharedAddressDeleteStatus(NULL, $contactId, TRUE);
             if ($sharedAddressMessage['count'] > 0) {
                 $sharedAddressCount += $sharedAddressMessage['count'];
                 $sharedContactList = array_merge($sharedContactList, $sharedAddressMessage['contactList']);
             }
         }
         $this->_sharedAddressMessage = array('count' => $sharedAddressCount, 'contactList' => $sharedContactList);
         if ($sharedAddressCount > 0) {
             if (count($this->_contactIds) > 1) {
                 // more than one contact deleted
                 $message = ts('One of the selected contacts has an address record that is shared with 1 other contact.', array('plural' => 'One or more selected contacts have address records which are shared with %count other contacts.', 'count' => $sharedAddressCount));
             } else {
                 // only one contact deleted
                 $message = ts('This contact has an address record which is shared with 1 other contact.', array('plural' => 'This contact has an address record which is shared with %count other contacts.', 'count' => $sharedAddressCount));
             }
             CRM_Core_Session::setStatus($message . ' ' . ts('Shared addresses will not be removed or altered but will no longer be shared.'), ts('Shared Addesses Owner'));
         }
         // set in form controller so that queries are not fired again
         $this->set('sharedAddressMessage', $this->_sharedAddressMessage);
     }
 }
Exemple #2
0
 /** 
  * build all the data structures needed to build the form 
  * 
  * @return void 
  * @access public 
  */
 function preProcess()
 {
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, false);
     $this->_searchKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     // sort out whether it’s a delete-to-trash, delete-into-oblivion or restore (and let the template know)
     $config =& CRM_Core_Config::singleton();
     $values = $this->controller->exportValues();
     require_once 'CRM/Contact/Task.php';
     $this->_skipUndelete = (CRM_Core_Permission::check('access deleted contacts') and (CRM_Utils_Request::retrieve('skip_undelete', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::DELETE_PERMANENTLY));
     $this->_restore = (CRM_Utils_Request::retrieve('restore', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::RESTORE);
     if ($this->_restore && !CRM_Core_Permission::check('access deleted contacts')) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this contact.'));
     } else {
         if ($this->_skipUndelete && !CRM_Core_Permission::check('delete contacts')) {
             CRM_Core_Error::fatal(ts('You do not have permission to delete this contact.'));
         }
     }
     $this->assign('trash', $config->contactUndelete and !$this->_skipUndelete);
     $this->assign('restore', $this->_restore);
     if ($this->_restore) {
         CRM_Utils_System::setTitle(ts('Restore Contact'));
     }
     if ($cid) {
         require_once 'CRM/Contact/BAO/Contact/Permission.php';
         if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT)) {
             CRM_Core_Error::fatal(ts('You do not have permission to delete this contact. Note: you can delete contacts if you can edit them.'));
         }
         $this->_contactIds = array($cid);
         $this->_single = true;
         $this->assign('totalSelectedContacts', 1);
     } else {
         parent::preProcess();
     }
     $this->_sharedAddressMessage = $this->get('sharedAddressMessage');
     if (!$this->_restore && !$this->_sharedAddressMessage) {
         // we check for each contact for shared contact address
         require_once 'CRM/Core/BAO/Address.php';
         $sharedContactList = array();
         $sharedAddressCount = 0;
         foreach ($this->_contactIds as $contactId) {
             // check if a contact that is being deleted has any shared addresses
             $sharedAddressMessage = CRM_Core_BAO_Address::setSharedAddressDeleteStatus(null, $contactId, true);
             if ($sharedAddressMessage['count'] > 0) {
                 $sharedAddressCount += $sharedAddressMessage['count'];
                 $sharedContactList = array_merge($sharedContactList, $sharedAddressMessage['contactList']);
             }
         }
         $this->_sharedAddressMessage = array('count' => $sharedAddressCount, 'contactList' => $sharedContactList);
         if ($sharedAddressCount > 0) {
             if (count($this->_contactIds) > 1) {
                 //more than one contact is deleted
                 CRM_Core_Session::setStatus(ts('Selected contact(s) has an address record which is shared with %1 other contact(s). Shared addresses will not be removed or altered but will no longer be shared.', array(1 => $sharedAddressCount)));
             } else {
                 // only one contact is been deleted
                 CRM_Core_Session::setStatus(ts('This contact has an address record which is shared with %1 other contact(s). Shared addresses will not be removed or altered but will no longer be shared.', array(1 => $sharedAddressCount)));
             }
         }
         // set in form controller so that queries are not fired again
         $this->set('sharedAddressMessage', $this->_sharedAddressMessage);
     }
 }